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是包管理

问题

pip下载速度慢

pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /Users/<user>/.config/pip/pip.conf

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文件)。

Could not find a version that satisfies the requirement cv2

安装cv2报错:

ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none)
ERROR: No matching distribution found for cv2

解决方案:pip3 install opencv-python,安装成功。

no module named cv2

某个Python脚本import cv2后,PyCharm报错提示:no module named cv2

解决方案:快捷键Ctrl + Shift + S打开Settings,找到Project,点击Python interpreter,看到如下界面,可见这个列表里面没有我们要使用的包opencv-python
在这里插入图片描述
点击加号,搜索opencv-python,提示No information available。点击Manage Repositories,删除默认的,增加豆瓣源:
在这里插入图片描述
问题解决。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

johnny233

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值