Post your Python module in detail

Source: Internet
Author: User
Tags add numbers
When we were learning Python, besides installing some modules with Pip, we sometimes downloaded the installation package from the website, and I wanted to make my own module into such a package, how to do it, how to publish it?

The following four steps are required:

1. First create a folder for the module.

To give a simple chestnut, you wrote a add.py module file with an Add method to implement the addition. This first step requires you to create a folder. and copy the add.py into this folder, for simplicity's sake, 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, such as the following example, and the specific metadata can be different from the example:

From Distutils.core import setupsetup (    name    = ' Add ',    version   = ' 1.0.0 ',    py_modules = [' Add '],    author   = ' Huilan ',    author_email= ' womende218@126.com ',    url     = ' http://www.lalalala.com ',    descriptioin= ' Add 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 make a release file using Python's own publishing tools.
Open a terminal in the Add folder, or CMD command line CD to the Add folder, execute the following command:

Python3 setup.py sdist

4. Install the publishing module into your local python.

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

sudo python3 setup.py Install

Look at the release information on the screen to confirm that the installation was successful and the release is ready.

Finally we get the following folder structure:

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 root directory are code files
-Dist\add-1.0.0.tar.gz is a release package
-ADD.PYC is a compiled version code
-setup.py storing meta data

The above is the release of your Python module data collation, follow-up continue to supplement the relevant information, thank you for the 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.