Using Setup to package Python code

Source: Internet
Author: User

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:

    1. Name Packaging names
    2. Version versions
    3. ....
    4. Playforms supported platforms, for example only 2.7
    5. Package_dir Source Directory
    6. Packages directories to be packaged under the source directory
    7. Py_modules modules that need to be packaged
    8. Requires defining dependent modules
    9. ...

Specific parameters can be found in the official website

Using Setup to package Python code

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.