ä¸ãæ¹æ³1ï¼ åæ件模å
ç´æ¥ææ件æ·è´å° $python_dir/Lib
äºãæ¹æ³2ï¼ å¤æ件模åï¼å¸¦setup.py
ä¸è½½æ¨¡åå
ï¼è¿è¡è§£åï¼è¿å
¥æ¨¡åæ件夹ï¼æ§è¡ï¼
python setup.py install
ä¸ã æ¹æ³3ï¼easy_install æ¹å¼
å
ä¸è½½ez_setup.py,è¿è¡python ez_setup è¿è¡easy_installå·¥å
·çå®è£
ï¼ä¹åå°±å¯ä»¥ä½¿ç¨easy_installè¿è¡å®è£
packageäºã
easy_install packageName
easy_install package.egg
åã æ¹æ³4ï¼pip æ¹å¼
å
è¿è¡pipå·¥å
·çå®è£
ï¼easy_install pipï¼pip å¯ä»¥éè¿easy_install å®è£
ï¼èä¸ä¹ä¼è£
å° Scripts æ件夹ä¸ãï¼
å®è£
ï¼pip install PackageName
æ´æ°ï¼pip install -U PackageName
移é¤ï¼pip uninstall PackageName
æç´¢ï¼pip search PackageName
帮å©ï¼pip help
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
注ï¼è½ç¶Pythonç模åå¯ä»¥æ·è´å®è£
ï¼ä½æ¯ä¸è¬æ
åµä¸æ¨èå¶ä½ä¸ä¸ªå®è£
å
ï¼å³åä¸ä¸ªsetup.pyæ件æ¥å®è£
ã
setup.pyæ件ç使ç¨å¦ä¸:
% python setup.py build #ç¼è¯
% python setup.py install #å®è£
% python setup.py sdist #å¶ä½ååå
% python setup.py bdist_wininst #å¶ä½windowsä¸çååå
% python setup.py bdist_rpm
setup.pyæ件çç¼å
setup.pyä¸ä¸»è¦æ§è¡ä¸ä¸ª setupå½æ°ï¼è¯¥å½æ°ä¸å¤§é¨åæ¯æè¿°æ§ä¸è¥¿ï¼æ主è¦çæ¯packagesåæ°ï¼ååºææçpackageï¼å¯ä»¥ç¨èªå¸¦çfind_packagesæ¥å¨æè·åpackageãæ以setup.pyæ件çç¼åå®é
æ¯å¾ç®åçã
ç®åçä¾å:
setup.pyæ件ï¼
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()
setupä¸çscripts表示å°è¯¥æ件æ¾å° PythonçScriptsç®å½ä¸ï¼å¯ä»¥ç´æ¥ç¨ãOKï¼ç®åçå®è£
æåï¼å¯ä»¥è¿è¡æå举çå½ä»¤çæå®è£
å
ï¼æè
å®è£
该pythonå
ãæ¬æºæµè¯æå(win32-python25)ï¼
é注ï¼setuptoolså·¥å
·å®è£
æ¹æ³
ï¼æ¹æ³ä¸ï¼. 使ç¨ez_setup.pyå®è£
setuptools
ããè¿å
¥
https://pypi.python.org/pypi/setuptoolsä¸è½½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ä¸è½½å°åï¼è§æ©å±é
è¯»ï¼ å®è£
å®åï¼æ好确ä¿
ï¼æ¹æ³äºï¼. 使ç¨å®æ´çå®è£
å
å®è£
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ä¸ä¸éè¦æ³¨æè¿ä¸ªé®é¢ã