简体   繁体   English

如何使用 python2.7 pip 而不是默认的 pip

[英]how to use python2.7 pip instead of default pip

I just installed python 2.7 and also pip to the 2.7 site package.我刚刚将 python 2.7 和 pip 安装到 2.7 站点 package。

When I get the version with:当我得到版本时:

pip -V

It shows:表明:

pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)

How do I use the 2.7 version of pip located at:如何使用位于以下位置的 pip 的 2.7 版本:

/usr/local/lib/python2.7/site-packages

There should be a binary called "pip2.7" installed at some location included within your $PATH variable.应该在 $PATH 变量中包含的某个位置安装一个名为“pip2.7”的二进制文件。

You can find that out by typing你可以通过输入找到

which pip2.7

This should print something like '/usr/local/bin/pip2.7' to your stdout.这应该会在您的标准输出中打印类似 '/usr/local/bin/pip2.7' 的内容。 If it does not print anything like this, it is not installed.如果它不打印任何类似的内容,则表示未安装。 In that case, install it by running在这种情况下,通过运行安装它

$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2.7 get-pip.py

Now, you should be all set, and现在,你应该已经准备好了,并且

which pip2.7

should return the correct output.应该返回正确的输出。

An alternative is to call the pip module by using python2.7, as below:另一种方法是使用python2.7调用pip模块,如下:

python2.7 -m pip <commands>

For example, you could run python2.7 -m pip install <package> to install your favorite python modules.例如,您可以运行python2.7 -m pip install <package>来安装您喜欢的 Python 模块。 Here is a reference: https://stackoverflow.com/a/50017310/4256346 .这是一个参考: https : //stackoverflow.com/a/50017310/4256346

In case the pip module has not yet been installed for this version of python, you can run the following:如果尚未为该版本的 python 安装 pip 模块,您可以运行以下命令:

python2.7 -m ensurepip

Running this command will "bootstrap the pip installer".运行此命令将“引导 pip 安装程序”。 Note that running this may require administrative privileges (ie sudo ).请注意,运行它可能需要管理权限(即sudo )。 Here is a reference: https://docs.python.org/2.7/library/ensurepip.html and another reference https://stackoverflow.com/a/46631019/4256346 .这是一个参考: https : //docs.python.org/2.7/library/ensurepip.html和另一个参考https://stackoverflow.com/a/46631019/4256346

as noted here , this is what worked best for me:如注意这里,这是为我工作最好的:

sudo apt-get install python3 python3-pip python3-setuptools

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

With Homebrew : 使用Homebrew

$ brew install python@2
$ pip2

You can also use python2 to get to its matching Python. 你也可以使用python2来获得匹配的Python。

pip has now dropped support for python2, therefore you can't use python2 pip pip现在已经放弃了对 python2 的支持,因此你不能使用 python2 pip

You can't find python2-pip in apt-get anymore, and you won't get pip when installing python2 from source你在apt-get里找不到python2-pip了,从源码安装python2也不会得到pip

You can still install python modules using apt-get .您仍然可以使用apt-get安装 python 模块。 To install a python prepend 'python-' to the module name要安装 python,请在模块名称前添加“python-”

apt-get install python-six  # install six

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM