发布于2019-08-06 19:25 阅读(2330) 评论(0) 点赞(1) 收藏(2)
一、如何安装pip
Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具。
通过以下命令查看pip和pip3是否已安装:
pip -V
pip3 -V
如果提示还未安装,则可通过以下方式安装:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
;sudo python get-pip.py
sudo python3 get-pip.py
pip -V
和pip3 -V
二、如果执行pip3 -v
出现以下错误提示:
$ pip3 -V
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 573, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 891, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 19.1.1 (/usr/local/lib/python3.7/site-packages), Requirement.parse('pip==18.0'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.0/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3098, in <module>
@_call_aside
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3082, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3111, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 575, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 588, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 777, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==18.0' distribution was not found and is required by the application
尝试执行sudo pip3 install setuptools --upgrade
,仍然报此错误。
解决方法:
python -c "import django; print(django.__path__)"
或python3
进入后import sys
->sys.path
,结果如下:$ python3
Python 3.7.0 (default, Jul 23 2018, 20:22:55)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/xulinzhou/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']
>>>
然后打开目录open /usr/local/Cellar/python/3.7.0/bin
,然后用sublime等编辑器打开pip3文件如下:
#!/usr/local/opt/python/bin/python3.7
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==18.0','console_scripts','pip3'
__requires__ = 'pip==18.0'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==18.0', 'console_scripts', 'pip3')()
)
把里面的pip==18.0
改成对应报错的版本号即可,我这里改成pip==19.1.1
,然后,保存。
最后,再次执行pip3 -V
,如下:
$ pip3 -V
pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
至此,问题得到解决。
链接:https://www.pythonheidong.com/blog/article/9356/59da58c13ce9c6335077/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!