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!