After the source code is finished, it will be installed as a package:
1. My source code structure is as follows:
Pack
|---src
| -Common---http
---user
| -Lib
| -factory.py
2. Implement setup.py
#!/usr/bin/env Python3#-*-coding:utf-8-*- fromDistutils.coreImportSetupsetup (Name='MD5', Version='1.0', Description='SDK for di input, output and Param', author=' Sam', Author_email=' Sam@qq. com', the URL="', License='No License', Platforms='Python 2.7', Py_modules=['Factory'], Package_dir={"':'Pack'}, Packages=['Lib','common.http'])
Perform
Python setup.py sdist
setup.py Sibling directory generates a Dist folder, which is sdk1.0.tar.gz
You can unzip it later.
Install after decompression:
Note: The use of setup.py does not have the uninstall function, if need to uninstall to manually delete
You can also use:--record records the Directory of installation files
Python setup.py install--record file.txt
Uninstall to use scripts for automatic installation and uninstallation
Note 1:
setup.py parameter Description
#python setup.py Build # Compilation
#python setup.py Install #安装
#python setup.py sdist #生成压缩包 (zip/tar.gz)
#python setup.py Bdist_wininst # Generate NT Platform installation package (. exe)
#python setup.py bdist_rpm # Generate RPM Package
or direct "Bdist Package Format " , the format is described as follows:
#python setup.py bdist--help-formats
--formats=rpm RPM Distribution
--formats=gztar gzip ' Ed tar file
--formats=bztar bzip2 ' Ed tar file
--formats=ztar Compressed tar file
--formats=tar tar file
--formats=wininst Windows Executable Installer
--formats=zip zip file
Note 2:setup parameters:
- Name Packaging names
- Version versions
- ....
- Playforms supported platforms, for example only 2.7
- Package_dir Source Directory
- Packages directories to be packaged under the source directory
- Py_modules modules that need to be packaged
- Requires defining dependent modules
- ...
Specific parameters can be found in the official website
Using Setup to package Python code