0
点赞
收藏
分享

微信扫一扫

pip使用问题汇总


概述

pip是最常用的python包管理工具,类似于Java的maven。

常用命令

下载指定版本的包
​​​pip install twisted==13.1.0​​​ 升级pip
​python -m pip install --upgrade pip​

easy_install、pip、pip3

easy_install

安装:​​easy_install <package>​​​或者​​easy_install "包名 == 包的版本号"​​​ 升级:​​easy_install -U "包名 >= 包的版本号"​

pip

Python通用包管理工具,提供对 Python 包的查找、下载、安装、卸载的功能。
安装:​​​pip install 包名​​​或者​​pip install 包名 == 包的版本号​​​ 升级:如果不提供version号,升级到最新版本;​​pip install --upgrade 包名 >= 包的版本号​​ 删除:​​pip uninstall 包名​

pip3

如果系统中只安装Python2,则只能使用pip。
如果系统中只安装Python3,则可使用pip和pip3,二者等价。
如果系统中同时安装Python2和Python3,则pip默认给Python2用,pip3指定给Python3用。
虚拟环境中,若只存在一个python版本,可以认为在用系统中pip和pip3命令都是相同。

对比

easy_install和pip都是用来下载安装python的一个公共资源库PyPI的相关资源包的,pip是easy_install的改进版,提供更好的提示信息,删除package等功能,老版本的python只有easy_install,没有pip
easy_install打包和发布Python包
pip是包管理

问题

Mac安装TensorFlow

输入命令:
​​​sudo pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl​​ 提示:

csrutil disable
csrutil: failed to modify system integrity configuration. This tool needs to be executed from the Recovery OS

重启系统​​enable csrutil​​即可。

Mac安装pip失败

Mac用​​home-brew​​​安装pip:​​brew install pip​​ 报错:

Error: No available formula with the name "pip"
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.org/en/stable/installing/#install-pip

由此可见,在home-brew中,pip的安装是跟python一起的。
换种方式:
​​​sudo easy_install pip​

Could not find a version that satisfies the requirement * (from versions: )

执行命令:​​pip install glob​​,报错信息如下:

Collecting glob
Could not find a version that satisfies the requirement glob (from versions: )
No matching distribution found for glob

解决方案1:
​​​pip install glob --allow-external glob --allow-unverified glob​​​ 依旧不行:
​DEPRECATION: --allow-external/--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.​​ 解决方案2:
网络搜索资源发现glob的包分glob2和glob3,分别用于Python2和Python3,很多pip包有这种问题/现象。故而解决方案:​​pip install glob3​

解决​​pip install *​​失败的常规思路:确定包名的正确性,网络问题重试,使用管理员权限或sudu权限,使用whl文件安装(先下载whl文件)。


举报

相关推荐

0 条评论