https://packaging.python.org/installing/#install-pip-setuptools-and-wheel
“如果你从 python.org 安装了 Python 2 >=2.7.9 或 Python 3 >=3.4,那么你将已经拥有 pip 和 setuptools,”
或许,或许不是:
我确实有 pip2 和 Python 2.7.10 和 2.7.12。后者是我当前的系统默认设置。我在 Ubuntu 16.04 上。显然我没有在系统范围内安装 pip2。我可以使用 pip2 从预先存在的 venv 内部创建一个新的 venv:
(cannon)malikarumi@Tetuoan2:~/Projects/cannon$ pyvenv Projects/memory
(cannon)malikarumi@Tetuoan2:~/Projects/cannon$ cd New2.7Projects/memory
(cannon)malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ deactivate
note change of outer folder name
malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ source bin/activate
(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$
然而,
(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ pip list
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named 'pip'
(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ pip2 list
The program 'pip2' is currently not installed. You can install it by typing:
sudo apt install python-pip
这表明我只有 Ubuntu 上的 Python 2,而且它默认没有安装 pip(或 pip2、virtualenv 或 pyvenv),即使它比 2.7.9 更新。这是正确的吗?为什么?如果不是,我该如何调用 pip?
如果你要告诉我从 pypi 中 curl 它:
malikarumi@Tetuoan2:~/Projects/cannon$ sudo -H curl https://bootstrap.pypa.io/get-pip.py | sudo python
[sudo] password for malikarumi:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1558k 100 1558k 0 0 626k 0 0:00:02 0:00:02 --:--:-- 626k
...< some nonsense about pip and sudo’s -H flag which I have followed but which changes nothing. Note that on this particular attempt the -H flag is there>...
Requirement already up-to-date: pip in /home/malikarumi/.local/lib/python2.7/site-packages
我该做什么?谢谢。
--更新-- 我的错误。我创建的 venv 里面有 Python 3.4。我以为默认情况下,如果您从某个解释器/版本中创建 venv,您将自动获得该解释器/版本,但事实并非如此。我更加困惑,因为 3.4 不是我的系统默认版本。我不知道那里发生了什么,但显然我仍然需要 2.7 venv 和 pip 的帮助。谢谢