我有一台 Macbook Air,想安装 pip。我有更新的 python 版本。我按照所有说明进行操作,但无法安装任何软件包。
我已经研究了 1 个多小时,看了很多文章和问题,但我无法弄清楚。
这是我尝试安装 pip 时终端上显示的内容,然后安装一个名为 beautifulsoup 的包:
arnau@MacBook-Air-de-Arnau ~ % python --version
Python 2.7.16
arnau@MacBook-Air-de-Arnau ~ % curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1840k 100 1840k 0 0 320k 0 0:00:05 0:00:05 --:--:-- 439k
arnau@MacBook-Air-de-Arnau ~ % python get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
Using cached pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.2
Uninstalling pip-20.2.2:
Successfully uninstalled pip-20.2.2
WARNING: The scripts pip, pip2 and pip2.7 are installed in '/Users/arnau/Library/Python/2.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
NOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.
Successfully installed pip-20.2.2
arnau@MacBook-Air-de-Arnau ~ % pip install beautifulsoup4
zsh: command not found: pip
arnau@MacBook-Air-de-Arnau ~ %
我不明白发生了什么或我应该如何解决错误。
原文由 Arnold Gee 发布,翻译遵循 CC BY-SA 4.0 许可协议
查看最后的警告,它说这些脚本不在 PATH 中。打开 Finder,将列出的文件复制到以下目录:/usr/local/bin/
转到 /Users/arnau/Library/Python/2.7/bin。复制 /usr/local/bin/ 中列出的文件,以便命令行可以识别您的命令 pip。
如果你不想这样做(我不建议这样做),你现在可以简单地使用其他答案说使用
python -m pip
,它将命令行定向到当前目录这些文件,/Users/arnau/Library/Python/2.7/bin。但是,您将来可能会遇到问题,因此我提出了上述答案。我还希望您不想在每次必须安装软件包时都输入额外的 2 个关键字。