Release your Python module details, python module details

Source: Internet
Author: User

Release your Python module details, python module details

When we are learning Python, apart from installing some modules with pip, sometimes we will download the installation package from the website and install it. I also want to make my own modules into such an installation package, what should we do and how should we release it?

The following four steps are required:

1. Create a folder for the module.

For example, you wrote an add. py module file, which contains an add method to implement addition. In this step, you need to create a folder. And copy add. py to this folder. For simplicity, we name the folder add.

Add
|__ Add. py

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

Edit this file and add the following code. This file contains metadata about the release, as shown in the following example. 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 two numbers',  )

3. Build a publishing file.

Now we have a folder that contains two files: the module code is put in add. py, and the related metadata is put in setup. py. Next, we will use the release tool provided by Python to create a release file.
Open a terminal in the add folder, or run the cmd command line cd to the add folder and run the following command:

Python3 setup. py sdist

4. Install the release module in your local Python.

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

Sudo python3 setup. py install

Check that the release information appears on the screen. confirm that the installation is successful and the release is ready.

The folder structure is as follows:

Add
|__ MANIFEST
|__ Build
| |__ Lib
| |__ Add. py
|__ Dist
| |__ Add-1.0.0.tar.gz
|__ Add. py
|__ Add. pyc
|__ Setup. py

Where:

-MANIFEST: This file contains the list of released files.
-Both 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 the compiled version code.
-Setup. py stores metadata

The above is to sort out the materials for releasing your Python module. We will continue to add relevant materials later. Thank you for your support for this site!

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.