如何使用Python 3的pip。在Python 2. x

时间:2022-11-30 21:09:16

I installed Python 3.x (besides Python 2.x on Ubuntu) and slowly started to pair modules I use in Python 2.x.

我安装了Python 3。x(除了Python 2。然后慢慢地开始对我在Python 2.x中使用的模块进行配对。

So I wonder, what approach should I take to make my life easy by using pip for both Python 2.x and Python 3.x?

因此,我想知道,我应该采取什么方法来让我的生活更轻松,用pip来支持Python 2。x x和Python 3. ?

7 个解决方案

#1


129  

The approach you should take is to install pip for Python 3.2.

您应该采取的方法是为Python 3.2安装pip。

You do this in the following way:

你可以这样做:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

Then, you can install things for Python 3.2 with pip-3.2, and install things for Python 2-7 with pip-2.7. The pip command will end up pointing to one of these, but I'm not sure which, so you will have to check.

然后,您可以使用pip-3.2为Python 3.2安装东西,并使用pip-2.7安装Python 2-7的东西。pip命令将指向其中的一个,但我不确定是哪个,所以您必须检查。

#2


33  

What you can also do is to use apt-get:

你也可以使用apt-get:

apt-get install python3-pip

In my experience this works pretty fluent too, plus you get all the benefits from apt-get.

在我的经验中,这也很流利,而且你从apt-get中得到了所有的好处。

#3


28  

First, install Python 3 pip using:

首先,使用以下方法安装Python 3 pip:

sudo apt-get install python3-pip

Then, to use Python 3 pip use:

然后,使用Python 3 pip使用:

pip3 install <module-name>

For Python 2 pip use:

对于Python 2 pip使用:

pip install <module-name>

#4


14  

If you don't want to have to specify the version every time you use pip:

如果您不希望每次使用pip时都必须指定版本:

Install pip:

pip安装:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

and export the path:

和出口的路径:

$ export PATH=/Library/Frameworks/Python.framework/Versions/<version number>/bin:$PATH

#5


5  

This worked for me on OS X: (I say this because sometimes is a pain that mac has "its own" version of every open source tool, and you cannot remove it because "its improvements" make it unique for other apple stuff to work, and if you remove it things start falling appart)

这为我工作在OS X:(我这样说是因为有时是一个mac的疼痛“自己的”版本的开源工具,你不能删除它,因为“改进”让其他苹果独特的东西,如果你删除它事情开始下降时直升机)

I followed the steps provided by @Lennart Regebro to get pip for python 3, nevertheless pip for python 2 was still first on the path, so... what I did is to create a symbolic link to python 3 inside /usr/bin (in deed I did the same to have my 2 pythons running in peace):

我按照@Lennart Regebro提供的步骤获得了python 3的pip,但是python 2的pip仍然是第一步,所以…我所做的是在/usr/bin中创建一个与python 3的符号链接(实际上,我做了同样的事情,让我的两条蟒蛇在和平中运行):

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/pip /usr/bin/pip3

ln - s /图书馆/框架/ Python.framework /版本/ 3.4 / bin / pip /usr/bin/pip3

Notice that I added a 3 at the end, so basically what you have to do is to use pip3 instead of just pip.

注意,我在最后加了一个3,所以基本上你要做的是使用pip3而不是pip。

The post is old but I hope this helps someone someday. this should theoretically work for any LINUX system.

这篇文章很旧,但我希望有一天它能帮到别人。这在理论上应该适用于任何LINUX系统。

#6


3  

On Suse Linux 13.2, pip calls python3, but pip2 is available to use the older python version.

在Suse Linux 13.2上,pip调用python3,但是pip2可以使用旧的python版本。

#7


0  

Please note that on msys2 I've found these commands to be helpful:

请注意,在msys2中,我发现这些命令是有用的:

$ pacman -S python3-pip
$ pip3 install --upgrade pip
$ pip3 install --user package_name

#1


129  

The approach you should take is to install pip for Python 3.2.

您应该采取的方法是为Python 3.2安装pip。

You do this in the following way:

你可以这样做:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

Then, you can install things for Python 3.2 with pip-3.2, and install things for Python 2-7 with pip-2.7. The pip command will end up pointing to one of these, but I'm not sure which, so you will have to check.

然后,您可以使用pip-3.2为Python 3.2安装东西,并使用pip-2.7安装Python 2-7的东西。pip命令将指向其中的一个,但我不确定是哪个,所以您必须检查。

#2


33  

What you can also do is to use apt-get:

你也可以使用apt-get:

apt-get install python3-pip

In my experience this works pretty fluent too, plus you get all the benefits from apt-get.

在我的经验中,这也很流利,而且你从apt-get中得到了所有的好处。

#3


28  

First, install Python 3 pip using:

首先,使用以下方法安装Python 3 pip:

sudo apt-get install python3-pip

Then, to use Python 3 pip use:

然后,使用Python 3 pip使用:

pip3 install <module-name>

For Python 2 pip use:

对于Python 2 pip使用:

pip install <module-name>

#4


14  

If you don't want to have to specify the version every time you use pip:

如果您不希望每次使用pip时都必须指定版本:

Install pip:

pip安装:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

and export the path:

和出口的路径:

$ export PATH=/Library/Frameworks/Python.framework/Versions/<version number>/bin:$PATH

#5


5  

This worked for me on OS X: (I say this because sometimes is a pain that mac has "its own" version of every open source tool, and you cannot remove it because "its improvements" make it unique for other apple stuff to work, and if you remove it things start falling appart)

这为我工作在OS X:(我这样说是因为有时是一个mac的疼痛“自己的”版本的开源工具,你不能删除它,因为“改进”让其他苹果独特的东西,如果你删除它事情开始下降时直升机)

I followed the steps provided by @Lennart Regebro to get pip for python 3, nevertheless pip for python 2 was still first on the path, so... what I did is to create a symbolic link to python 3 inside /usr/bin (in deed I did the same to have my 2 pythons running in peace):

我按照@Lennart Regebro提供的步骤获得了python 3的pip,但是python 2的pip仍然是第一步,所以…我所做的是在/usr/bin中创建一个与python 3的符号链接(实际上,我做了同样的事情,让我的两条蟒蛇在和平中运行):

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/pip /usr/bin/pip3

ln - s /图书馆/框架/ Python.framework /版本/ 3.4 / bin / pip /usr/bin/pip3

Notice that I added a 3 at the end, so basically what you have to do is to use pip3 instead of just pip.

注意,我在最后加了一个3,所以基本上你要做的是使用pip3而不是pip。

The post is old but I hope this helps someone someday. this should theoretically work for any LINUX system.

这篇文章很旧,但我希望有一天它能帮到别人。这在理论上应该适用于任何LINUX系统。

#6


3  

On Suse Linux 13.2, pip calls python3, but pip2 is available to use the older python version.

在Suse Linux 13.2上,pip调用python3,但是pip2可以使用旧的python版本。

#7


0  

Please note that on msys2 I've found these commands to be helpful:

请注意,在msys2中,我发现这些命令是有用的:

$ pacman -S python3-pip
$ pip3 install --upgrade pip
$ pip3 install --user package_name