Detailed explanation of the two commonly used installation methods of Python modules

高洛峰
Release: 2017-03-26 16:27:05
Original
1486 people have browsed it

Python module installation method
1. Method 1: Single file module
Copy the file directly to $python_dir/Lib2. Method 2: Multi-file module, with setup.pyDownload the module package, unzip it, enter the module folder, execute:
python setup.py install
3. Method 3: easy_install methodFirst Download ez_setup.py, run python ez_setup to install the easy_install tool, and then use easy_install to install the package.
easy_install packageName
easy_install package.egg4. Method 4: pip method
First install the pip tool: easy_install pip (pip can be installed through easy_install, and will also be installed in Scripts folder.) Install: pip install PackageName
Update: pip install -U PackageName
Remove: pip uninstall PackageName
Search: pip search PackageName
Help: pip help------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ---------------------------------------------
Note: Although Python modules can be copied and installed, it is generally recommended to create an installation package, that is, write a setup.py file for installation.
The setup.py file is used as follows:
% python setup.py build #Compile
% python setup.py install #Install
% python setup.py sdist #Create a distribution package
% python setup.py bdist_wininst #Create a distribution package under windows
% python setup.py bdist_rpmsetup.py file writing
setup.py mainly executes a setup function, most of which are descriptive things, and the most The main thing is the packages parameter, which lists all packages. You can use the built-in find_packages to dynamically obtain packages. So writing the setup.py file is actually very simple.
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.pyimport sys
def get():
return sys.pathscripts/test.pyimport os
print os.environ .keys()
The scripts in setup means that the file is placed in the Python Scripts directory and can be used directly. OK, the simple installation is successful. You can run the listed commands to generate the installation package, or install the python package. The local test was successful (win32-python25)!
Note: setuptools tool installation method

(Method 1). Use ez_setup.py to install setuptools

Enter https://pypi .python.org/pypi/setuptoolsDownload ez_setup.py
This is an installation method that setuptools is proud of. It only requires a script ez_setup.py of about 8K in size, which can automatically install many software for users, including setuptools itself. Python package. Using this method, users only need to download ez_setup. py and run, you can automatically download and install the appropriate setuptools egg file suitable for the user's current Python version (of course, users need Python 2.3.5 or above, and users of 64-bit operating systems need Python 2.4 or above). In addition, this script will also install the executable easy_install script to the location where Python executable scripts should normally be installed on all user operating systems (for example, Windows users will install it in the Scripts directory under the Python installation directory). For more detailed instructions and precautions about this installation method, please refer to its official instructions (see further reading). The simple installation command is as follows: wget -q ez_setup. py download address (see extended reading) After installation, it is best to ensure

(Method 2). Use the complete installation package to install setuptools

Of course, users can also Install directly using the setuptools release version. This is also a very convenient method for users using Windows. The official package management repository of many Linux distributions contains a version of setuptools. For example, if you use Ubuntu like me, installing setuptools is as simple as the following:
# apt-get install python-setuptools

Install easy_install package-name, such as easy_install pylab

Module uninstall easy_install -m package-name, such as easy_install -m pylab

easy_install -m package name, you can uninstall the software package, but After uninstalling, you have to manually delete the remaining files.

setuptools can automatically install modules. You only need to provide it with a module name, and it will automatically help you solve module dependency problems. Under normal circumstances, modules installed using setuptools will automatically be placed in a directory with the suffix .egg.
In Windows, the easy_install command is in the scripts in the python installation directory, so you need to add the scripts to the PATH of the environment variable, which makes it more convenient to use. You don’t need to pay attention to this problem under Linux.

The above is the detailed content of Detailed explanation of the two commonly used installation methods of Python modules. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!