Python uses setuptools to package and upload it to the PyPi library.

Source: Internet
Author: User

I recently wrote a python magic lamp generator. We can see that many python libraries are installed with setup. py and easy_install, So we plan to try it out. I tried to find it extremely simple. So take some notes.
Reference articles:
• Setuptools developer documentation
• Cute Python: Use setuptools to hatch Python egg
Preparations
Everything is hard to start with. If you want your python code to use easy_install and setup. py, you must make the following preparations:
1. Install python's setuptools package
2. Your code must be in the package. That is, your code cannot appear in the root directory. It should be in a directory with init. py.
Write your setup. py script
For the purpose of recording my thoughts, I will not start with Hello world. I will put the setup. py of the library SlideGen directly. According to each line, you should understand.

Setup (
Name = 'slidegen ',
Version = '0. 0.0.1 pre ',
Packages = ['slidegen '],
Author = 'reyoung ',
Author_email = 'reyoung @ 126.com ',
License = 'lgpl ',
Install_requires = ["PyYAML> = 3.10", "Markdown >=2.1.1", "tornado >=2.2"],
Description = "A HTML5 Slide Generator in python ",
Entry_points = {
'Console _ scripts ':[
'Slidegen = SlideGen. slidegen: main'
]
},
Keywords = 'html5 slide generator ',
Url = 'https: // github.com/reyoung/SlideGen'
)
This code needs to write a file named setup. py in the root directory, including the above Code in setup. py.
You must include a function called setup. In this function, you can set the parameters of the code package. Some parameters are described as follows:
• Packages: package included in your code library. This packages can be multiple or automatically executed through find_packages. However, manual operations are also good.
• Install_requires: The third-party library required by your code library. If you do not remember what third-party libraries are used in your code, you can use yolk to display all third-party libraries managed under setuptools.
You can use easy_install yolk to install yolk.
Query the packages managed by easy_install using the command yolk-l
• Entry_points is an automatically generated executable program that is generated in the Python */Scripts/directory. Where:
O lele_scripts is the command line program generated
O gui_scripts is a graphical interface program generated
The format of o equals to the right is as follows: "[executable program name] = introduced package name. Sub-package name. Module name: entry function"
Use setup. py
Install
After setup. py is written, the installation becomes very simple. Directly run the python setup. py install command to complete the installation.
Debug/uninstall
I have not found a method to uninstall using the python script, but you can use python setup. py install -- record install.txtto include all the installed files in install.txt. You can use rm to delete these files for uninstallation.
Upload to the PyPi version Library
After uploading pypi, others can use easy_install XXX to install it.
Upload is also very simple. You only need one command.
Setup. py register sdist bdist_egg upload
The result of using this command will upload your code to pypi. Note the following:
• If you have not registered a pypi account, he will prompt you to register a pypi account in the command line and follow the steps below. Verify the email address.
• If you choose to remember the password, it will store your password in your % HOME % \. pypirc (in linux, yes ~ /. Pypirc). Note that the format of the Stored Password is incorrect. You need to manually add the [server-login] section. The format is as follows:
...
[Server-login]
Username: XXXXXX
Password: XXXXXX (plaintext)
In this way, you can upload python code to the pypi version library.

 


From reyoung1110

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.