python module installation

 

Python module installation


1. The single-file module
directly copies the file to $python_dir/Lib

2. Multi-file module, with setup.py
python setup.py install

3. 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, write a setup.py file to install.
The usage of the setup.py file is as follows:
% python setup.py build #compile
% python setup.py install 
 #installation % python setup.py sdist #make    a distribution package % python setup.py bdist_wininst #make a distribution package under windows % python setup .py bdist_rpm  
   

Writing the setup.py file
setup.py mainly executes a setup function, most of which are descriptive things, the most important is the packages parameter, which lists all the packages, and can use the built-in find_packages to dynamically obtain the package. So the writing of 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.py

import sys
def get():
 return sys.path    

scripts/test.py

import os
print os.environ.keys() 

The scripts in setup means that the file is placed in the Scripts directory of Python 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 native test was successful (win32-python25)!


Four, setuptools tool installation

a. Install setuptools using ez_setup.py

  这是 setuptools 自豪的一种安装方式,只需要一个大约 8K 作为的脚本ez_setup。py,就能自动为用户安装包括 setuptools 自身在内的许多 Python 包。   使用这种方式,用户只需要下载 ez_setup。py 并运行,就可以自动下载和安装适合用户当前 Python 版本的适当的 setuptools egg 文件(当然,用户需要 Python 2.3.5 以上的版本,64 位操作系统的用户则需要 Python 2.4 以上的版本)。此外,这段脚本还会将可执行的 easy_install 脚本安装到用户所有的操作系统 Python 可执行脚本正常应该安装的位置(例如,Windows 用户会安装到 Python 安装目录下的 Scripts 目录中)。关于这种安装方法的更详细说明和注意事项,请参考其官方说明(见扩展阅读)。简单的安装命令如下:   wget -q ez_setup。py下载地址(见扩展阅读) 安装完后,最好确保

b. 使用完整的安装包安装setuptools

  当然,用户也可以直接使用 setuptools发布版本来安装。对于使用 Windows 的用户,这也是挺方便的方法,许多 Linux 发行版的官方包管理仓库都包含 setuptools 的某个版本。例如,如果你跟我一样使用 Ubuntu ,那安装 setuptools 只是简单的进行如下操作:
# apt-get install python-setuptools

安装模块

  easy_install package-name,比如 easy_install pylab

模块卸载

   easy_install -m package-name, 比如easy_install -m pylab  
       easy_install -m 包名,可以卸载软件包,但是卸载后还要手动删除遗留文件。

setuptools它可以自动的安装模块,只需要你提供给它一个模块名字就可以,并且自动帮你解决模块的依赖问题。一般情况下用setuptools给安装的模块会自动放到一个后缀是.egg的目录里。

在Windows里,easy_install这个命令在python安装目录下的scripts里面,所以需要把scripts加到环境变量的PATH里,这样用起来就更方便,linux下不需要注意这个问题。

 

转载于http://blog.163.com/yang_jianli/blog/static/161990006201162152724339/

使用总结,还是用easy_install安装方式合适,他会根据模块的依赖关系,下载所有的安装包。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326633710&siteId=291194637