Several common ways to install Python modules

Source: Internet
Author: User

Python module installation


One, single file module
Copy the file directly to the $python _dir/lib

Two, multi-file module, with setup.py
Python setup.py Install

Third, egg file
1) Download ez_setup.py, run Python ez_setup
2) Easy_install *.egg
Note: Although Python modules can be copied and installed, it is generally recommended to make an installation package, that is, to write a setup.py file to install.
The setup.py file is used as follows:
% python setup.py build #编译
% python setup.py install #安装
% python setup.py sdist #制作分发包
% python setup.py bdist_wininst #制作windows下的分发包
% python setup.py bdist_rpm

Preparation of setup.py files
The main implementation of a setup function in setup.py, most of which is descriptive, the most important is the packages parameter, lists all the package, you can use their own find_packages to dynamically obtain the package. So the setup.py file is actually very simple to write.
A simple example:
setup.py file:

From Setuptools import Setup, find_packages
Setup
Name = "MyTest",
Version = "0.10",
Description = "My Test module",
Author = "Robin Hood",
url = "Http://www.csdn.net",
license = "LGPL",
Packages = Find_packages (),
Scripts = ["scripts/test.py"],
)

mytest.py

Import Sys
Def get ():
Return Sys.path

scripts/test.py

Import OS
Print Os.environ.keys ()

The scripts in setup indicates that the file is placed in the Python scripts directory and can be used directly. OK, a simple installation succeeds, you can run the commands listed to build the installation package, or install the Python package. Native test succeeded (WIN32-PYTHON25)!


Iv. Installation of Setuptools tools

A. Installing Setuptools with ez_setup.py

This is setuptools proud of a way of installation, only need a script of about 8K as Ez_setup.   PY, you can automatically install many Python packages, including Setuptools itself, for the user. In this way, users only need to download ez_setup. Py and run, you can automatically download and install the appropriate Setuptools egg file for the user's current Python version (of course, users need Python 2.3. More than 5 versions, 64-bit operating system users will need python more than 2.4 version). In addition, the script installs the executable Easy_install script to a location where the user's operating system Python executable scripts should be installed (for example, Windows users are installed in the Scripts directory in the Python installation directory). For more detailed instructions and precautions on this installation method, please refer to their official instructions (see extended reading). The simple installation command is as follows: Wget-q Ez_setup. PY (see extended reading) after installation, it is best to ensure that

B. Installing with a full installation package Setuptools

Of course, users can also install them directly using the Setuptools release version. This is also a handy way for users who use Windows, and many of the official package management repositories for Linux distributions contain a version of Setuptools. For example, if you're using Ubuntu the same way as I do, installing setuptools is simply doing the following:
# Apt-get Install Python-setuptools

Mounting module

Easy_install Package-name, such as Easy_install Pylab

Module uninstallation

Easy_install-m Package-name, such as Easy_install-m Pylab
EASY_INSTALL-M package name, you can uninstall the package, but also manually delete the legacy files after uninstallation.

Setuptools It can automatically install the module, just need you to give it a module name can be, and automatically help you solve the module dependency problem. In general, the modules installed with Setuptools will automatically be placed in a directory with a suffix of. Egg.

In Windows, easy_install This command in the Python installation directory under the scripts, so you need to add scripts to the environment variable path, so it is more convenient to use, Linux does not need to pay attention to this problem.

Reproduced in http://blog.163.com/yang_jianli/blog/static/161990006201162152724339/

Use summary, or the Easy_install installation method is appropriate, he will be based on the module dependencies, download all the installation package.

Several common ways to install Python modules

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.