پیکیج های پایتون معمولا یک ساختار استاندارد دارند که در خود سایت اصلی طریقه ساخت به طور کامل توضیح داده شده است.
Creating a Package — The Hitchhiker\'s Guide to Packaging v1.0 documentation -> http://guide.python-distribute.org/creation.html
برای نصب پیکیج های پایتون چند راه وجود دارد.
استفاده از source
کلا اگر پکیج استاندارد باشد یک فایل setup.py است. که با اجرای خط زیر پکیج به pythonpath سیستم می رود.
$ python setup.py install
دقت کنید که حتما sudo er باشید
استفاده از easy_install
برنامه ای به اسم setuptools وجود دارد که از طریق repository سیستم عاملتان می توانید نصبش کنید.
$ apt-get install python-setuptools
حالا شما می خواهید package django را نصب کنید. کافیست در ترمینال تایپ کنید
$ easy_install django Searching for django Reading http://pypi.python.org/simple/django/ Reading http://www.djangoproject.com/ Best match: Django 1.3.1 Downloading http://pypi.python.org/packages/source/D/Django/Django-1.3.1.tar.gz#md5=62d8642fd06b9a0bf8544178f8500767 ^Cinterrupted
ای وای بر من D: می خواستم ورژن ۱.۲.۵ را نصب کنم خوب چه کنم؟ حالا به easy_install ورژن برنامه ای که می خواهم را نیز می گویم.
$ easy_install django==1.2.5 Searching for django==1.2.5 Reading http://pypi.python.org/simple/django/ Reading http://www.djangoproject.com/ Best match: Django 1.2.5 Downloading http://pypi.python.org/packages/source/D/Django/Django-1.2.5.tar.gz#md5=e031ea3d00996035e49e4bfa86e07c40 Processing Django-1.2.5.tar.gz Running Django-1.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-JlBUNe/Django-1.2.5/egg-dist-tmp-aNgfJX
به همین سادگی package با همان ورژنی که می خواستم نصب شد.
راهنمای کاملش را در زیر می بینید
EasyInstall - The PEAK Developers\' Center -> http://peak.telecommunity.com/DevCenter/EasyInstall
استفاده از pip
یک برنامه دیگر هم هست به اسم pip که به نسبت کامل تر است. برای استفاده برنامه را نصب کنید.
$ apt-get install python-pip
حالا چند مدل دستور دارید
$ pip search babel Babel - Internationalization utilities INSTALLED: 0.9.6 (latest) Flask-Babel - Adds i18n/l10n support to Flask applications INSTALLED: 0.8 (latest) nibabel - Access a multitude of neuroimaging data formats openbabel-python - openbabel: Python interface to the Open Babel chemistry library MakoLang - This package adds preprocessor to mako for convenient syntax of gettext strings, and babel extractor to process such templates. BabelDjango - Utilities for using Babel in Django BabelGladeExtractor - Babel Glade XML files translatable strings extractor chemfp - chemfp is a set of command-lines tools for generating cheminformatics fingerprints and searching those fingerprints by Tanimoto similarity, as well as a Python library which can be used to build new tools. These algorithms are designed for the dense, 100-10,000 bit fingerprints which occur in small-molecule/pharmaceutical chemisty. The Tanimoto search algorithms are implemented in C for performance and support both threshold and k-nearest searches. Fingerprint generation can be done either by extracting existing fingerprint data from an SD file or by using an existing chemistry toolkit. chemfp supports the Python libraries from Open Babel, OpenEye, and RDKit toolkits. gpsbabel - Python wrapper for GPSBabel project $ pip install babel $ pip install SQLAlchemy --upgrade Downloading/unpacking SQLAlchemy Downloading SQLAlchemy-0.7.4.tar.gz (2.5Mb): 2.5Mb downloaded Running setup.py egg_info for package SQLAlchemy warning: no files found matching \'*.jpg\' under directory \'doc\' no previously-included directories found matching \'doc/build/output\' Installing collected packages: SQLAlchemy Found existing installation: SQLAlchemy 0.6.8 Uninstalling SQLAlchemy: Successfully uninstalled SQLAlchemy Running setup.py install for SQLAlchemy building \'sqlalchemy.cprocessors\' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c lib/sqlalchemy/cextension/processors.c -o build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/processors.o gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/processors.o -o build/lib.linux-x86_64-2.7/sqlalchemy/cprocessors.so building \'sqlalchemy.cresultproxy\' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c lib/sqlalchemy/cextension/resultproxy.c -o build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/resultproxy.o gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/resultproxy.o -o build/lib.linux-x86_64-2.7/sqlalchemy/cresultproxy.so warning: no files found matching \'*.jpg\' under directory \'doc\' no previously-included directories found matching \'doc/build/output\' Successfully installed SQLAlchemy Cleaning up... $ pip uninstall simplejson Uninstalling simplejson: /home/me/env/lib/python2.7/site-packages/simplejson /home/me/env/lib/python2.7/site-packages/simplejson-2.2.1-py2.7.egg-info Proceed (y/n)? y Successfully uninstalled simplejson
کلا امکانات زیادی دارد. از مجموعه امکاناتی که من در pip خیلی دوست داشتم ساخت فایل requirement است. به طور مثال می خواهید یک مجموعه ای از برنامه ها را دانلود کنید. یک لیست از برنامه ها را در یک فایل بگذارید و به دستور زیر همه را دانلود کنید. من همچین فایلی ساختم و همیشه بعد از نصب سیستم عامل جدید این فایل را اجرا می کنم.
$ pip install -r requirements