Publish your Python module detailed _python

Source: Internet
Author: User

When we learn python, in addition to the use of PIP to install some modules, sometimes from the Web site download installation package down to install, I also want to write my own module to make such an installation package, how to do, how to release it?

The following four steps are probably required:

1. First create a folder for the module.

For a simple chestnut, you write a add.py module file, which has an Add method that implements addition. This first step will require you to create a folder. and copy add.py into this folder, and for simplicity, we'll name the folder add

Add
|__add.py

2. Then create a file named "setup.py" in the new folder.

Edit this file to add the following code. This file contains metadata about the publication, as in the following example, the specific metadata can differ from the example:

From Distutils.core Import setup

Setup (
    name    = ' Add ',
    version   = ' 1.0.0 ',
    py_modules = [' Add '] ,
    author   = ' Huilan ',
    author_email= ' womende218@126.com ',
    url     = ' http://www.lalalala.com ' ,
    descriptioin= ' Add two numbers ',
  )

3. Build a publishing file.

Now we have a folder that contains two files: The module code is placed in the add.py, and the relevant metadata is placed in the setup.py. Next we use Python's own publishing tools to make the release file.
Open a terminal in the Add folder, or CMD command line CD to the Add folder, and execute the following command:

Python3 setup.py sdist

4. Install the release module into your local python.

Still in the terminal that you just opened, enter the following command:

sudo python3 setup.py Install

Look at the screen on the release of information, confirm the installation is successful, the release is ready.

Finally we get the folder structure as follows:

Add
|__ MANIFEST
|__ Build
| |__ Lib
| |__ add.py
|__ Dist
| |__ add-1.0.0.tar.gz
|__ add.py
|__ ADD.PYC
|__ setup.py

which

-Manifest This file contains a list of files in the publication
-Build\lib\add.py and add.py in the root directory are code files
-Dist\add-1.0.0.tar.gz is the release package
-ADD.PYC is compiled version code
-setup.py storage of meta data

The above is the release of your Python module data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.