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\Scripts
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文件,你可以手動刪除。
參考:http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html