Python中的easy_install安装

来源:互联网 发布:python soa框架 编辑:程序博客网 时间:2024/04/29 14:15

Python中的easy_install工具很爽,它的作用类似于Php中的pear,或者Ruby中的gem,或者Perl中的cpan。

如果想使用easy_install工具,可能需要先安装setuptools,不过更酷的方法是使用ez_setup.py脚本:

wget -q http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py

安装完后,最好确保easy_install所在目录已经被加到PATH环境变量里:

Windows: C:\Python25\Scrip_ts
Linux: /usr/local/bin

比如说要安装Python的MySQL支持,可以执行如下命令,系统会自动在pypi网站列表里查找相关软件包:

easy_install MySQL-python

如果你在Windows+python2.5上执行如上命令的话,可能会出现如下错误:

Processing MySQL-python-1.2.3c1.tar.gz
Running MySQL-python-1.2.3c1\setup.py -q bdist_egg --dist-dir c:\docume~1\...
\locals~1\temp\easy_install-fvvfve\MySQL-python-1.2.3c1\egg-dist-tmp-q9moxf
error: The system cannot find the file specified

出现这类错误的原因是选错了版本,针对这个案列,我们可以显式指定软件包的版本号:

easy_install "MySQL-python==1.2.2"

通过easy_install安装软件,相关安装信息会保存到easy-install.pth文件里,路径类似如下形式:

Windows:C:\Python25\Lib\site-packages\easy-install.pth
Linux:/usr/local/lib/python25/site-packages/easy-install.pth

如果想删除通过easy_install安装的软件包,比如说:MySQL-python,可以执行命令:

easy_install -m MySQL-python

此操作会从easy-install.pth文件里把MySQL-python的相关信息抹去,剩下的egg文件,你可以手动删除。

python - easy_install的安装和使用

  1. 为什么要装easy_install?
    正常情况下,我们要给Python安装第三方的扩展包,我们必须下载压缩包,解压缩到一个目录,然后命令行或者终端打开这个目录,然后执行
    python setup.py install
    来进行安装。
    这样是不是很繁琐呢?如果我们直接命令行执行
    easy_install Twisted
    就把最新版的Twisted包装上去了,是不是很爽呢?
    所以easy_install就是为了我们安装第三方扩展包更容易
  2. 怎么装easy_install?
    首先下载easy_install的安装包,下载地址:
    http://pypi.python.org/pypi/setuptools
    下载自己对应的版本,windows上面直接运行exe安装就可以了
    linux上面可以直接运行
    sh setuptools-0.6c9-py2.4.egg
    安装完成后,easy_install会被自动复制到bin目录下,也就是我们的PATH路径下,所以我们在终端中可以直接运行easy_install命令了
    easy_install Twisted
    测试一下,看是否成功
  3. 常见的问题
    当在安装包的时候,不管是手动安装 还是 easy_install,如果提示错误:找不到python.h文件,那说明我们安装的python不是开发版,在ubuntu下面的解决办法如下:
    sudo apt-get install python-2.7-dev
    安装对应python版本的dev就可以了。

转自http://www.cnblogs.com/huangjacky/archive/2012/03/28/2421866.html 和http://xiaolin0199.iteye.com/blog/585524