python pip的安装和使用

python pip的安装和使用


(1)下载get-pip.py脚本执行。

python get-pip.py

官方文档介绍 和下载   https://pip.pypa.io/en/latest/installing.html
注意ubuntu上  使用apt-get install python-pip 获得


(2)pip install -U  [软件包的名称]

例如:
pip install -U bottle

(3)使用说明

安裝套件:pip install PackageName

更新套件:pip install -U PackageName

移除套件:pip uninstall PackageName

搜索套件:pip search PackageName

显示说明:pip help


官方教程: https://wiki.python.org/moin/CheeseShopTutorial

pip的帮助文件:

C:\Python27\Lib\site-packages>pip -help

Usage:
  pip [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.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  -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                Path to a verbose appending log.
  --proxy             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout             Set the socket timeout (default 15 seconds).
  --exists-action    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --trusted-host   Mark this host as trusted, even though it does
                              not have valid or any HTTPS.
  --cert               Path to alternate CA bundle.
  --client-cert        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir           Store the cache data in .
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.


查看安装位置

shell> python >>> from distutils.sysconfig import get_python_lib

windows pip 下载安装位置
>>> print get_python_lib()            # Python v2.x
/Library/Python/2.7/site-packages

>>> print(get_python_lib())           # Python v3.x
/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages
ubuntu pip下载软件的 安装位置
/usr/local/python2.7/dist-package



注意,在windows上用pip安装库时,会提示安装 VCForPython27
官方地址: http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
这是一个C编译器
安装文件:
这个文件在win8/win10上安装时候,要用管理员命令行模式下
E:\>VCForPython27.msi
libpng warning: iCCP: Not recognizing known sRGB profile that has been edited


注意:如果要在windows上安装,把 c:\python27\tools\script 这个加到环境变量中
  • Starting from Python versions 2.7.9 and 3.4.0, pip is already included in the regular install, see matth's answer below. Check if the path to the Scripts directory inside your Python installation directory is contained in your system's PATH environment variable, so pip can be found.

  • A very straightforward approach (as of March 2014) for many other setups is to follow these instructions from pip.pypa.io, namely download get-pip.py and run python get-pip.py (may require admin access). Note that pip.exe will be placed inside your Python installation's Scripts folder, which is likely not on your path (fix that by running C:\PythonXX\Tools\Scripts\win_add2path.py).

  • You can install and use pip inside a virtual environment. And again, if you install a recent Python 3.4 VENV, pip will most likely already be included. If it is not available there, you can run python get-pip.py inside the virtual environment, see above. See also thegauraw's answerbelow.


国内的第三方镜像豆瓣镜像的使用

——http://pypi.douban.com/simple/ 

1.安装easy_install
    先安装easy_install,有了这个工具便可安装其他的python扩展库。工具网址——http://pypi.douban.com/simple/setuptools/
    在该网页中选择合适的版本,例如本机中的python版本为2.7.6,操作系统为windows,那么应选择 setuptools-0.6c11.win32-py2.7.exe
    顺利安装完easy_install之后,应把easy_install加入环境变量。easy_install.exe位于python安装目录的script文件夹下。(别告诉我你不会修改环境变量)

2.使用easy_install安装扩展库
    例如安装requests扩展库(一种简单实用的HTTP通信工具),那么可以在控制台中输入以下命令
#注意,下面这条安装命令是好使的,requests前面有一个空格,这个空格是必须的,安装其他库的时候也要有。至于为什么我也不知道,总之加上就对了。
    easy_install -i http://pypi.douban.com/simple/ requests
    easy_install -i 选项可以设置镜像网址,这里指定到国内的豆瓣镜像。安装需要一些时间,不过只用您等待一小会。
    安装完之后可尝试安装是否成功,可以通过以下python测试:
    若执行正确,那么status_code的结果应为200

安装示例:
这里安装了一个should 断言库,注意should前有空格
C:\Python27\Lib\site-packages>easy_install.py -i http://pypi.douban.com/simple/ should 
Searching for should 
Reading http://pypi.douban.com/simple/should/
Best match: should 0.4.5 
Downloading http://pypi.douban.com/packages/source/s/should/should-0.4.5.tar.gz#md5=4b3322fdd5e829565d319e4b389
83779 
Processing should-0.4.5.tar.gz 
Writing c:\users\admini~1\appdata\local\temp\easy_install-cnenad\should-0.4.5\setup.cfg 
Running should-0.4.5\setup.py -q bdist_egg --dist-dir c:\users\admini~1\appdata\local\temp\easy_install-cnenad\ 
should-0.4.5\egg-dist-tmp-hmqbdy 
Adding should 0.4.5 to easy-install.pth file 

Installed c:\python27\lib\site-packages\should-0.4.5-py2.7.egg 
Processing dependencies for should 
Finished processing dependencies for should




你可能感兴趣的:(python)