300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 「Python」Mac下pip出现command not found和Could not find a version that satisfies the requirement ...解决方式

「Python」Mac下pip出现command not found和Could not find a version that satisfies the requirement ...解决方式

时间:2021-03-03 12:51:58

相关推荐

「Python」Mac下pip出现command not found和Could not find a version that satisfies the requirement ...解决方式

两个报错的解决方式在第2和3

问题描述command not found解决方式Could not find a version that satisfies the requirement...(from versions: ) No matching distribution found for ...解决方式相关解释

需使用python第三方库时,需要单独提前安装,一般这些库都已经被python的pip源收录,在os中的shell中使用pip install进行安装。

问题描述

Python下载包时 语句pip出现command not find

本次我安装的是中文分词工具包jieba,windows的shell应该会出现下图的顺利情况:

在我的macOS下,出现了命令没有找到的提示:

command not found解决方式

shell对Python解释器使用-m运行ensurepip

python -m ensurepip

在shell运行上述指令后,报错和几个exception

ERROR:

OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'

解决方式是 以管理员的身份再次执行python -m ensurepip指令

具体操作如下:

在终端执行命令,输入sudo su -,后输入密码(不知道为啥我没输密码就进去了

切换为root权限后重新输入python -m ensurepip指令,显示Successfully installed pip-6.1.1下载成功。

ctrl+D可退出root权限后,输入pip下载jieba库指令,可以开始下载了。

Could not find a version that satisfies the requirement…(from versions: ) No matching distribution found for …解决方式

又报错。好不容易能下载了,但是什么包都找不到有什么用呢0.0

按照提示原因,怀疑是版本问题,看了下pip与python的版本号,python在mac中内置又python2,另外我又已经安装了python3。

python -Vpip -V

更新pip的指令是:

python -m pip install --upgrade pip

我又查看了pip3的版本号,也许可以使用pip3命令来下载所需要的包。

指令为pip3 install jieba,终于成功了!!!

下载好慢哦

原来当一台机器的python有多个版本时,用pip3就可以自动区分用Python3来安装库。是为了避免和Python2发生冲突的。

P.S.报错原因也很可能很可能是国内的网络问题,下不下来,详见可能考虑到是python国内网络的问题,这时我们用国内的镜像源来加速

最后可输入pip list或者pip3 list查看已经下载了的包与库,确认一下~

相关解释

其中python -m的作用是

python -m xxx.py 作用是:把xxx.py文件当做模块启动

常用的:

开启静态服务器 python -m SimpleHTTPServer 8888

python3 改为 python3 -m http.server 8888

查看python文档 python -m pydoc -p 8888

格式化json

echo ‘{“name”:“python”,“version”:“2.7”}’ | python -m json.tool

{

“name”: “python”,

“version”: “2.7”

}

python xxx.py

python -m xxx.py

这是两种加载py文件的方式:

1叫做直接运行

2把模块当作脚本来启动(注意:但是__name__的值为’main’ )

不同的加载py文件的方式,sys.path 不同

其中ensurepip是Python 2.7.9 发布后的新模块,所有安装都提供 “pip” 包管理器,详细见:whatsnew in 2.7

其中PEP 477中的内容

PEP 477: Backport ensurepip (PEP 453) to Python 2.7 PEP 477 approves

the inclusion of the PEP 453 ensurepip module and the improved

documentation that was enabled by it in the Python 2.7 maintenance

releases, appearing first in the Python 2.7.9 release.

。。。。

以及ensurepip — Bootstrapping the pip installer

以及pip3的相关解释

pip和pip3的区别

其实这两个命令效果是一样的,没有区别:

比如安装库openpyxl,pip3 install openpyxl或者pip install openpyxl:只是当一台电脑同时有多个版本的Python的时候,用pip3就可以自动区分用Python3来安装库。是为了避免和Python2发生冲突的。

(2)如果你的电脑只安装了Python3,那么不管用pip还是pip3都一样的。

安装了python3之后,会有pip3

(1)使用pip install XXX :

新安装的库会放在这个目录下面:python2.7/site-packages

(2)使用pip3 install XXX :

新安装的库会放在这个目录下面:python3.7/site-packages

(3)如果使用python3执行程序,那么就不能importpython2.7/site-packages中的库。

参考:

[python]自问自答:python -m参数?

Python安装后没有pip for Mac

开发工具-ensurepip:安装Python包安装工具

Python安装cv2库出错及解决:Could not find a version that satisfies the requirement cv2

Python出现Could not find a version that satisfies the requirement openpyxl (from versions: )

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。