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所在目錄已經(jīng)被加到PATH環(huán)境變量里:
Windows: C:\Python25\Scripts
Linux: /usr/local/bin
比如說要安裝Python的MySQL支持,可以執(zhí)行如下命令,系統(tǒng)會(huì)自動(dòng)在pypi網(wǎng)站列表里查找相關(guān)軟件包:
easy_install MySQL-python
如果你在Windows+python2.5上執(zhí)行如上命令的話,可能會(huì)出現(xiàn)如下錯(cuò)誤:
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
出現(xiàn)這類錯(cuò)誤的原因是選錯(cuò)了版本,針對(duì)這個(gè)案列,我們可以顯式指定軟件包的版本號(hào):
easy_install “MySQL-python==1.2.2″
通過easy_install安裝軟件,相關(guān)安裝信息會(huì)保存到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,可以執(zhí)行命令:
easy_install -m MySQL-python
此操作會(huì)從easy-install.pth文件里把MySQL-python的相關(guān)信息抹去,剩下的egg文件,你可以手動(dòng)刪除。
參考:http://www.ibm.com/developerworks/cn/linux/l-cppeak3.html