Sample code:
Create a new test.py file with the following contents:
[Python]View PlainCopy
- Print "Show Me"
Create a new setup.py compilation file with the following content:
[Python]View PlainCopy
- From Distutils.core Import Setup
- Setup (name=' MyBlog ', #打包后的包文件名
- version=' 1.0 ',
- description=' My Blog distribution Utilities ',
- author=' Liu tiansi ',
- author_email=' [email protected] ',
- Url=' http://blog.liuts.com ',
- py_modules=[' test '], #与前面的新建文件名一致
- )
run the following command:
>>python setup.py sdist #打包后的格式为tar. Gz/zip
Operation Result:
A new dist directory is added to the current directory, which will have a package with the same name value. Under Windows Zip package, Linux is the tar.gz package.
Install and test:
Unzip the newly packaged file and run the following command to install it:
Python setup.py Install
Enter the Python interpreter environment and run the following command:
Import Test
Success if the word show me is printed successfully
Uninstall:
Python setup.py Uninstall
the setup functions are detailed in each parameter:
>>python setup.py--help
--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 List of directories that need to be packaged
--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
setup.py Packing command each parameter detailed:
>>python setup.py--help-commands
--python setup.py Build # Compile-only not installed
--python setup.py Install #安装到python安装目录的lib下
--python setup.py sdist #生成压缩包 (zip/tar.gz)
--python setup.py bdist_wininst #生成NT平台安装包 (. exe)
--python setup.py bdist_rpm #生成rpm包
or "Bdist package format" in the following format:
#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
Such as:
Python setup.py bdist--formats=zip equivalent to Python setup.py sdist
Packaging setuptools for Python modules