Python Package Management Tool FAQ

Source: Internet
Author: User

Python Package Management Tool FAQ

    • This article link: http://zengrong.net/post/2169.htm

Python Packaging

First, confusion

As a beginner of Python, I was quite puzzled by the package management (well, it's confusing). The main performance in the following several aspects:

    1. What is the difference between these package management tools?
    2. Distutils
    3. Setuptools
    4. Distribute
    5. Disutils2
    6. Distlib
    7. Pip
    8. When should I use PIP, when should it setup.py be used, do they matter?
    9. easy_install,,, ez_setup.py setup.py and setup.cfg What are the differences?
    10. The relationship between wheel and Pip?
    11. The relationship between Egg and WHL?
    12. How do I publish my own module (published to PyPI)?
    13. How do I make a private release of a module (not published to PyPI)?

In order to understand these problems, I found a lot of information. Finally found the best data is the official Python document.

Here is a summary of all the information I have found, hoping to help a few months later to forget all of the self.

Ii. Python package management tool Big mess

I use chronological order to describe the process of fighting.

1. Distutils

Distutils is part of the Python standard library, released in 2000. It is used to install and publish Python modules.

Setup.py is written using the function of distutils, we can see a simple example of setup.py.

Here you can see all the detailed descriptions of the setupt.py format: Writing the Setup Script.

To install a module into the current Python environment, you can use the setup.py file provided by this module:

Setup.  Install 

The following code publishes a Python module that is packaged as a tar.gz or ZIP package:

Setup.  Sdist 

Can even be packaged as RPM or EXE installation packages:

Setup.  bdist_rpmsetup.  Bdist_wininst    
2. Setuptools and distribute

Setuptools is a collection developed for the enhancement of Distutils, released in 2004. It contains easy_install this tool.

Ez_setup.py is the installation tool for Setuptools. ezis easy the abbreviation.

Simply put, Setuptools is the name of a project and is the base component. easy_installThis is the tool that is provided in this project, and it relies on the underlying components to work.

To facilitate the description, the Setuptools mentioned in the following article is considered easy_install synonymous with.

Use Setuptools to automatically download, build, install, and manage Python modules.

For example, install a package from PyPI:

Sqlobject

Download a package file, and then install it:

HTTP://example.  COM/path/to/mypackage-1.2.  3.tgz               

Install from an. Egg format:

/my_downloads/otherpackage-3.2.  1-py2.  3.Egg           

Distribute is a branched version of Setuptools. The reason for branching may be that some developers think Setuptools development is too slow. But now, distribute has merged back into the Setuptools. So we can think of them as the same thing. In fact, if you look at easy_install the version, you will find that it is essentially distribute.

# easy_install--version0.6.    -
3. Eggs

The Eggs format is a file format introduced by Setuptools, which uses the. egg extension for the installation of a Python module.

Setuptools can recognize this format. And parse it, install it.

To learn more, you can look at this: the Quick Guide to Python Eggs.

Eggs is to pythons as Jars is to Java.

4. Pip

Note that starting from here, easy_install and setuptools no longer synonymous.

PIP is the current standard of fact for Python package management, released in 2008. It is used as easy_install a substitute, but it still has a lot of functionality built on the Setuptools component.

Pip wants to use the Eggs format (although it supports Eggs) rather than using the "source release" (created by use python setup.py sdict ). This makes full use of the convenient features provided by the Requirements File Format.

Pip can take advantage of requirments.txt to implement a dependent installation. In setup.py , there is also a install_requires table to specify the dependent installation. What is the difference between them? You can read this article: setup.py vs Requirements.txt (Chinese version).

PIP supports popular VCS systems such as GIT/SVN/HG, which can be installed directly from GZ or zip compression packs, support search packages, and specify server installation and other functions.

Pip vs Easy_install describes the difference in detail. They can be said to be the winning field, but Pip has a significant advantage.

5. Wheel

Wheel is essentially a ZIP package format that uses the. WHL extension for the installation of the Python module, which appears to replace the Eggs.

Wheel also provides an bdist_wheel extended command as a setuptools that can be used to generate a wheel package.

PIP provides a wheel subcommand to install the wheel package. Of course, the wheel module needs to be installed first.

Setup.cfg can be used to define information about wheel packaging.

Wheel vs Egg details The differences between the Wheel and Eggs formats, and it is clear that the Wheel advantage is obvious.

The Python Wheels Web site shows the share of Python modules released with Wheels on the PyPI.

Pypip.in also supports wheel.

6. Distutils2 and Distlib

DISTUTILS2 was designed as a substitute for distutils. Developed from 2009 to 2012. It contains more features and wants to packaging be part of the standard library as a name into Python 3.3. But the plan came to a halt.

Distlib is a part of DISTUTILS2, which distutils2/packaging adds advanced APIs to provide low-level functionality, making it easy to use.

Here are some reasons why Distlib did not enter the Python 3.3 standard library.

Therefore, you may not need to know these two tools for the time being, just watch them change.

Three, the choice of tools

If you look closely at the contents of the above, I believe you already know how to choose the current.

For starters like me, it's natural to use PIP instead of using it easy_install .

If the module is published, the wheel format is of course used.

Iv. release your own modules

For Python3 programmers, of course, you should read this first: distributing Python Modules.

In addition, Tutorial on packaging and distributing Projects are also sufficiently detailed and official.

And Python2 programmers should see this distributing Python Modules.

Of course, Setuptools's official documentation is also a good tutorial: Building and distributing Packages with Setuptools.

This tutorial can be used to get started: Sharing Your Labor of Love:pypi Quick and Dirty

As for how to publish your own module to PyPI or build your own private package Management Server, the above article has been very clear.

V. References

Most of the information mentioned above is found here, or referred to: Python packaging User Guide.

Thanks to this article, let me no longer tangled, and then resolved to write this article continue tangled: Differences between distribute, Distutils, Setuptools and DISTUTILS2?

This article is also quite broken: about setup.py in Python, and more than the example in this article.

Python Package Management Tool FAQ

Related Article

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.