python包的安装_安装python包

======================================

主要的 python package index server:

======================================

1. python 官网,  http://pypi.python.org

2. pythonxy 官网, http://code.google.com/p/pythonxy/

3. activepython 官网, http://www.activestate.com/activepython

4. enthought官网, http://www.enthought.com/products/epd.php

5. uci大学也提供编译好的 windows版包, 版本往往很新, http://www.lfd.uci.edu/~gohlke/pythonlibs

=============================

two installers: setuptools and pip

=============================

#step 1: setuptools, package installer, it is must when pip installation

http://pypi.python.org/pypi/setuptools/0.6c11

要运行包的setup.py脚本, 都需要setuptools

#step 2: pip, easy intall replacement

http://pypi.python.org/pypi/pip/1.2.1

======================================

关于windows下如何安装package

======================================

1. 选择 package 文件

python 的 package 大致分为2 类, 一类是纯python代码实现的(比如Flask), 另一类是C语言实现的(比如 cx_Oracle, PIL).  对于第一类, 可以选择下载源码的 tarball, 然后用pip 或 easy_install 安装即可. 对于第2类的包, 最好是选择编译好的installer安装包, 不要选择源码编译安装, 源码编译会涉及到c编译器以及很多依赖c库

2. 安装预编译好的installer安装包

这种installer多是通过 distutils 制作的, 直接双击 installer 会出现安装向导,  会让我们选择要安装在哪个 python 的 site_packages 下, 候选的 python 列表中(installer是从注册表中查到有哪些python), 不会包括通过 virtualenv 建立的 python 运行环境.  如果要将该包安装在 virtualenv下, 可以在该虚拟环境下通过 easy_install.exe 调用该installer,  比如:

(python27_flask) C:\python\python27_flask\Scripts>easy_install.exe D:\lxml-2.3.3.win32-py2.7.exe

当然, 还有一种笨办法, 就是双击installer将它安装到某个python下, 然后查看安装日志(比如libxml2-python-wininst.log), 找到installer复制了哪些文件, 再将这些文件手动复制到 virtualenv下的对应目录中.

======================================

如何使用pip

======================================

这个文章内容摘自下面的文档库

http://guide.python-distribute.org/index.html

http://guide.python-distribute.org/usage.html

http://guide.python-distribute.org/pip.html

1. Installing from a tarball

You can install directly from a tarball or zip file, as long as there is a working setup.py file in the root directory of the unzipped contents:

$ pip install path/to/mypackage.tgz

$ pip install http://dist.repoze.org/PIL-1.1.6.tar.gz

easy_installer也支持tarball直接安装.

In the setup.py there are only three required fields: name, version, and packages.This will look like:

from distutils.core import setup

setup(

name='TowelStuff',

version='0.1dev',

packages=['towelstuff',],

license='Creative Commons Attribution-Noncommercial-Share Alike license',

long_description=open('README.txt').read(),

)

2. Installing from a Version Control System (VCS)

$ pip install -editable  svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev

The repo URL must begin with svn+ (or hg+, git+, or bzr+) and end with #egg=packagename;

3. download MyApp from http://pypi.python.org and then install

$ pip install MyApp

4. download MyApp from other pypi respository

$ pip install MyApp -f http://www.somesite.com/my-packages/

5. install specific version

$ pip can parse ==, >=, >,

$ pip install 'Markdown<2.0'

$ pip install 'Markdown>2.0,<2.0.3'

6. Upgrade Markdown

$ pip install -U Markdown

7. uninstall Markdown

$ pip uninstall Markdown

8. to list installed packages and versions, use the freeze command:

$ pip freeze > /installed_packages.txt

9. use requirement description file to install many packages

$ pip install -r requirements.txt

##here is a requirement description file content,

Django==1.3.1

##add comment here

Markdown==2.1.0

你可能感兴趣的:(python包的安装)