pip使用问题汇总

勤奋不是嘴上说说而已,而是实际的行动,在勤奋的苦度中持之以恒,永不退却。业精于勤,荒于嬉;行成于思,毁于随。在人生的仕途上,我们毫不迟疑地选择勤奋,她是几乎于世界上一切成就的催产婆。只要我们拥着勤奋去思考,拥着勤奋的手去耕耘,用抱勤奋的心去对待工作,浪迹红尘而坚韧不拔,那么,我们的生命就会绽放火花,让人生的时光更加的闪亮而精彩。

导读:本篇文章讲解 pip使用问题汇总,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

概述

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,删除默认的,增加豆瓣源:
在这里插入图片描述
问题解决。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/142230.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!