Packaging setuptools for Python modules

Source: Internet
Author: User

Sample code:
Create a new test.py file with the following contents:

[Python]View PlainCopy
    1. Print "Show Me"


Create a new setup.py compilation file with the following content:

[Python]View PlainCopy
  1. From Distutils.core Import Setup
  2. Setup (name=' MyBlog ', #打包后的包文件名
  3. version=' 1.0 ',
  4. description=' My Blog distribution Utilities ',
  5. author=' Liu tiansi ',
  6. author_email=' [email protected] ',
  7. Url=' http://blog.liuts.com ',
  8. py_modules=[' test '], #与前面的新建文件名一致
  9. )


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

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.