First, the Construction tool setup.py application Scenario
When installing Python's related modules and libraries, we generally use "Pip Install Module name" or "Python setup.py install", the former is installed online, will install the relevant dependencies of the package, the latter is to download the source package and then installed locally, The dependent packages for the package are not installed. So using the PIP tool is fairly straightforward when installing a normal Python package. However, in the following scenario, using the Python setup.py install will be more appropriate for your needs:
When writing related systems, how does Python implement packaging and publishing together with dependent packages? If I develop a program on this machine, I need to use Python, MySQL module and the redis_run.py module I wrote. How do I implement a server to publish the system, how to implement the dependency module and its own module redis_run.py packaged together to achieve one-click installation? and install the redis_run.py module you wrote in EXE file format to Python's global execution path C:\Python27\Scripts? |
In this scenario, the PIP tool does not seem to be useful, it can only be used with the Python build tool setup.py, using this build tool to implement the above scenario requirements, simply state the dependent libraries and versions in the setup.py file, and then use Python on the target machine setup.py install installation.
Ii. introduction of setup.py
1 fromSetuptoolsImportSetup, Find_packages2 3 Setup (4Name ="Test", 5Version ="1.0", 6Keywords = ("Test","XXX"), 7Description ="EDS SDK", 8Long_description ="Eds SDK for Python", 9license ="MIT Licence", Ten OneURL ="http://test.com", AAuthor ="Test", -Author_email ="[email protected]", - thePackages =find_packages (), -Include_package_data =True, -Platforms =" any", -Install_requires = [], + -Scripts = [], +Entry_points = { A 'console_scripts': [ at 'test = Test.help:main' - ] - } -)
setup.py each parameter description:
--name Package Name --version (-V) package version author of the--author program e-mail address of the author of the--author_email program --maintainer Maintenance Person e-mail address of--maintainer_email maintainer --url program's website address licensing information for--license programs A brief description of the--description program detailed description of the--long_description program list of software platforms applicable to the--PLATFORMS program --classifiers Category List of programs --keywords List of key words for the program --packages Package Directory (folder containing __init__.py) that needs to be processed --py_modules List of Python files that need to be packaged of the--download_url program --cmdclass --data_files data files, tablets, configuration files, etc. that need to be packaged --scripts List of footsteps to be performed during installation --package_dir tells Setuptools which directories the files are mapped to which source package. An example: Package_dir = {': ' lib '}, which means that the modules in the "root package" are in the Lib directory. --requires defines which modules are dependent --provides defines which modules can provide dependencies --find_packages () for simple engineering, it's easy to manually add the packages parameter, and we've just used this function, which by default searches for each package containing __init__.py in the same directory as setup.py. In fact, we can put the package in a single src directory, in addition, this package may also have the Aaa.txt file and the Data folder. In addition, some specific packages can also be excluded. Find_packages (exclude=["*.tests", "*.tests.*", "tests.*", "tests"]) --install_requires = ["Requests"] dependent packages required for installation --entry_points Dynamic discovery Services and plugins, detailed below |
The following entry_points: Console_scripts indicates the name of the command-line tool,and in "Redis_run = RedisRun.redis_run:main", the name of the toolkit is indicated before the equal sign. The contents after the equals sign indicate the entry address of the program.
1 entry_points={'console_scripts': [2 ' Redis_run = RedisRun.redis_run:main ' , 3 ]}
There are multiple records here, so a project can make multiple command-line tools, such as:
1 setup ( 2 entry_points = { 3 " console_scripts " : [ 4 " foo = demo:test " 5 " bar = Demo:test " , 6 ]} 7 )
III. setup.py Project Sample code
1 #!/usr/bin/env python2 #Coding=utf-83 4 fromSetuptoolsImportSetup5 6 " "7 Package The Redis service as an EXE file under C:\Python27\Scripts8 " "9 Ten Setup ( OneName="Redisrun",#Name in PyPI, Pip or easy_install the name used when installing Aversion="1.0", -Author="Andreas Schroeder", -Author_email="[email protected]", theDescription= ("This is a service of Redis Subscripe"), -License="GPLv3", -keywords="Redis subscripe", -Url="Https://ssl.xxx.org/redmine/projects/RedisRun", +packages=['Redisrun'],#List of directories that need to be packaged - + #dependencies that need to be installed Ainstall_requires=[ at 'redis>=2.10.5', - 'setuptools>=16.0', - ], - - #Add this option to generate EXE files under scripts in the Python directory under Windows - #Note: A colon is between the module and the function: inentry_points={'console_scripts': [ - 'Redis_run = RedisRun.redis_run:main', to ]}, + - #long_description=read (' readme.md '), theclassifiers=[#List of categories to which the program belongs * "Development Status:: 3-alpha", $ "Topic:: Utilities",Panax Notoginseng "License:: OSI Approved:: GNU general public License (GPL)", - ], the #This entry is required, otherwise uninstall the Times Windows error +Zip_safe=False A)
Reference blog:
http://blog.csdn.net/lynn_kong/article/details/17540207
http://blog.csdn.net/pfm685757/article/details/48651389
http://blog.csdn.net/langb2014/article/details/53114341
Python's Build tool--setup.py file