pip安装及使用

Python2.7.9以上、 Python3.4以上版本都自带pip工具。

pip下载地址:https://pypi.python.org/pypi/pip#downloads

通过命令判断是否已安装,可显示版本和路径:pip --version

D:pytest>pip --version
pip 10.0.1 from D:pytestvenvlibsite-packagespip-10.0.1-py3.7.eggpip (python 3.7)

pip升级

D:pytest>pip install -U pip    # 需要指定路径,系统给出了错误提示
ERROR: To modify pip, please run the following command:
D:pytestvenvScriptspython.exe -m pip install -U pip

然而输入以上指令,仍然报错,解决方法:

D:pytest>D:pytestvenvScriptspython.exe -m pip install -U --force-reinstall pip

运行结果

(venv) D:pytest>D:pytestvenvScriptspython.exe -m pip install -U --force-reinstall pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3
703d2ddaf940/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 18.0
    Uninstalling pip-18.0:
      Successfully uninstalled pip-18.0
Successfully installed pip-18.0

安装包

pip install SomePackage # 最新版本
pip install SomePackage==1.0.4 # 指定版本
pip install 'SomePackage>=1.0.4' # 最小版本

列出已安装的包:pip list

D:pytest>pip list
Package    Version
---------- -------
pip        18.0
setuptools 39.1.0

查看可升级的包:pip list -o

D:pytest>pip list -o
Package    Version Latest Type
---------- ------- ------ -----
setuptools 39.1.0  40.0.0 wheel

你可能感兴趣的