Python package (module)

Source: Internet
Author: User
Python package management differences learning Python has been a period of time, often encounter the problem of installing a variety of packages, a while setuppy, a while easy_install, and a while pip Python package management differences

I have been learning Python for a while. I often encounter various package installation problems. py, easy_install for a while, pip for a while, and some concepts such as distutils and setuptools do not know who they are and when they should be used. I will clarify these concepts today.

Distutils

Distutils is part of the Python standard library. its original intention is to provide developers with a convenient packaging method and a convenient installation method.

For example, if you create a package named foo that contains a foo. py file, you want to package it for use by others. At this time, you need to write a setup. py file:

From distutils. core import setup

Setup (name = 'foo ',

Version = '1. 0 ',

Py_modules = ['foo'],

)

Then run the command

$ Python setup. py sdist

Then you can find that there is a foo-1.0.tar.gz package in the folder named dist. The package contains three files: foo. py, setup. py, PKG-INFO. The first two files are the same as the two files we mentioned earlier. PKG-INFO is some information about the package. Then you can install foo-1.0.tar.gz for others.

The installer only needs to decompress the foo-1.0.tar.gz file and then run the command.

$ Python setup install

This package will be automatically installed to the appropriate location of the system.

Setuptools

Setuptools is an enhancement to distutils, especially the introduction of package dependency management.

Setuptools can create egg files for Python packages. The relationship between Python and egg files is equivalent to the relationship between java and jar packages.

The easy_install script provided by setuptools can be used to install the egg package. In addition, easy_install can automatically download related packages from PyPI, complete installation, and upgrade.

Easy_install provides multiple installation methods to upgrade the Python package, for example:

Easy_install SQLObject

Easy_install-f http://pythonpaste.org/package_index.html SQLObject

Easy_install http://example.com/path/to/MyPackage-1.2.3.tgz

Easy_install/my_downloads/OtherPackage-3.2.1-py2.3.egg

Easy_install -- upgrade PyProtocols

Later, developers thought that the development of setuptools was too slow. fork went out of the Distribute project, and then in August 2013, Distribute merged back to setuptools 0.7.

Pip

Pip is a tool for installing and managing Python packages. It is an enhancement to easy_install. You can also automatically download the installation package from PyPI.

In pip,

All required packages must be downloaded before installation. Therefore, some packages are not installed, and others are not installed.

All installed packages will be tracked, so you can know why they are installed and can be uninstalled at the same time.

You do not need to use egg files.

Easy to use:

Pip install pkg_name

Pip uninstall pkg_name

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.