Python:pip
本文的运行环境为:MS Windows Se7en 64bit。
默认情况下,在Python安装完成后,你可以在它的根目录的“Scripts”文件夹中找到“pip”命令。
如下所示:
在MS Windows中,你需要将上图所示的路径(Path is:C:\Python27\Scripts)添加到系统的环境变量%PATH%中,才可以在系统的任意位置自由调用。
如下所示:
那么,什么是PIP?
Pip是Python的包管理器,Python官方维护了一个类似Github的项目,即:Pypi.python.org。
通过pip你可以将自己的代码分享到Pypi,也可以通过Pip拿到别人的共享。
Pip的基本使用:
查看当前Pip版本信息:
1 2 3 4 |
C:\Users\adamhuan>pip -V pip 1.5.6 from C:\Python27\lib\site-packages (python 2.7) C:\Users\adamhuan> |
获得Pip命令的帮助信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
C:\Users\adamhuan>pip Usage: pip <command> [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. bundle DEPRECATED. Create pybundles. help Show help for commands. General Options: -h, --help Show help. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log-file <path> Path to a verbose non-appending log, that only logs failures. This log is active by default at C:\Users\adamhuan\pip\pip.log. --log <path> Path to a verbose appending log. This log is inactive by default. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --cert <path> Path to alternate CA bundle. C:\Users\adamhuan> |
安装某个Python项目:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
C:\Users\adamhuan>pip install pyquery Collecting pyquery Downloading pyquery-1.2.9.zip (45kB) 100% |################################| 49kB 222kB/s Collecting lxml>=2.1 (from pyquery) Downloading lxml-3.4.2-cp27-none-win32.whl (3.0MB) 100% |################################| 3.0MB 81kB/s Collecting cssselect (from pyquery) Downloading cssselect-0.9.1.tar.gz Installing collected packages: cssselect, lxml, pyquery Running setup.py install for cssselect Running setup.py install for pyquery Successfully installed cssselect-0.9.1 lxml-3.4.2 pyquery-1.2.9 C:\Users\adamhuan> |
如果希望从特定的站点获取Python的代码,按如下所示的方式操作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
C:\Users\adamhuan>pip install tox --index-url http://pypi.douban.com/simple Collecting tox This repository located at pypi.douban.com is not a trusted host, if this repo sitory is available via HTTPS it is recommend to use HTTPS instead, otherwise yo u may silence this warning with '--trusted-host pypi.douban.com'. DEPRECATION: Implicitly allowing locations which are not hosted at a secure or igin is deprecated and will require the use of --trusted-host in the future. Downloading http://pypi.douban.com/packages/source/t/tox/tox-1.9.2.tar.gz (93k B) 100% |################################| 94kB 1.1MB/s Requirement already satisfied (use --upgrade to upgrade): virtualenv>=1.11.2 in c:\python27\lib\site-packages (from tox) Collecting py>=1.4.17 (from tox) This repository located at pypi.douban.com is not a trusted host, if this repo sitory is available via HTTPS it is recommend to use HTTPS instead, otherwise yo u may silence this warning with '--trusted-host pypi.douban.com'. Downloading http://pypi.douban.com/packages/source/p/py/py-1.4.26.tar.gz (190k B) 100% |################################| 192kB 1.5MB/s Installing collected packages: py, tox Running setup.py install for py Running setup.py install for tox Installing tox-script.py script to c:\Python27\Scripts Installing tox.exe script to c:\Python27\Scripts Installing tox.exe.manifest script to c:\Python27\Scripts Installing tox-quickstart-script.py script to c:\Python27\Scripts Installing tox-quickstart.exe script to c:\Python27\Scripts Installing tox-quickstart.exe.manifest script to c:\Python27\Scripts Successfully installed py-1.4.26 tox-1.9.2 C:\Users\adamhuan> |
——————————————————————————————
Done。