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!