为了安装 python 软件包,您必须安装 pip
。在这里可以找到非常清晰的说明:https://packaging.python.org/installing/
但是,当尝试通过 python get-pip.py
安装 pip 时,我收到以下错误:
操作系统错误:[Errno 13]权限被拒绝:'/Library/Python/2.7/site-packages/pip'
我尝试按照 GitHub ( https://github.com/pypa/pip/issues/3761 ) 上的建议更改我的权限并禁用系统完整性保护(如此链接 ( http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/ ) 所示),但没有效果。
另外,请注意,我的机器上不存在 pip
:
Myname-MBP:python myname$ pip
-bash: pip: command not found
我运行的是 OSX 10.12.2。
最佳答案
解决方案:
尝试了 Tristan 和 Coolq B 的建议 sudo python get-pip.py
后,它成功了。 但是,如果一开始没有成功,请重试:第一次尝试后,我遇到了超时错误。我又试了一次,成功了。两个结果均已发布:
第一次尝试(超时错误):
Myname-MBP:python myname$ sudo python get-pip.py
Password:
The directory '/Users/myname/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/myname/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
19% |██████▎ | 245kB 11kB/s eta 0:01:32Exception:
Traceback (most recent call last):
File "/tmp/tmpq4Sjum/pip.zip/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/tmp/tmpq4Sjum/pip.zip/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/tmp/tmpq4Sjum/pip.zip/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/tmp/tmpq4Sjum/pip.zip/pip/req/req_set.py", line 620, in _prepare_file
session=self.session, hashes=hashes)
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 821, in unpack_url
hashes=hashes
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 659, in unpack_http_url
hashes)
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 882, in _download_http_url
_download_url(resp, link, content_file, hashes)
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 603, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "/tmp/tmpq4Sjum/pip.zip/pip/utils/hashes.py", line 46, in check_against_chunks
for chunk in chunks:
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 571, in written_chunks
for chunk in chunks:
File "/tmp/tmpq4Sjum/pip.zip/pip/utils/ui.py", line 139, in iter
for x in it:
File "/tmp/tmpq4Sjum/pip.zip/pip/download.py", line 560, in resp_read
decode_content=False):
File "/tmp/tmpq4Sjum/pip.zip/pip/_vendor/requests/packages/urllib3/response.py", line 357, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/tmp/tmpq4Sjum/pip.zip/pip/_vendor/requests/packages/urllib3/response.py", line 324, in read
flush_decoder = True
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/tmp/tmpq4Sjum/pip.zip/pip/_vendor/requests/packages/urllib3/response.py", line 246, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
第二次尝试(成功):
MyName-MBP:python myname$ sudo python get-pip.py
Password:
The directory '/Users/myname/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/myname/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 143kB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 72kB/s
Installing collected packages: pip, wheel
Successfully installed pip-9.0.1 wheel-0.29.0
关于python - 为 Python 安装 pip 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41991390/