如何在Ubuntu上通过pip安装python3版本的软件包?

本文翻译自:How to install python3 version of package via pip on Ubuntu?

I have both python2.7 and python3.2 installed in Ubuntu 12.04 . 我在Ubuntu 12.04安装了python2.7python3.2
The symbolic link python links to python2.7 . 符号链接python链接到python2.7

When I type: 当我输入:

sudo pip install package-name

It will default install python2 version of package-name . 它将默认安装python2版本的package-name

Some package supports both python2 and python3 . 一些包支持python2python3
How to install python3 version of package-name via pip ? 如何通过pip安装python3版本的package-name


#1楼

参考:https://stackoom.com/question/jA3s/如何在Ubuntu上通过pip安装python-版本的软件包


#2楼

You may want to build a virtualenv of python3, then install packages of python3 after activating the virtualenv. 您可能想要构建一个python3的virtualenv ,然后在激活virtualenv之后安装python3的包。 So your system won't be messed up :) 所以你的系统不会搞砸:)

This could be something like: 这可能是这样的:

virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install package-name

#3楼

The easiest way to install latest pip2 / pip3 and corresponding packages: 安装最新的pip2 / pip3和相应软件包的最简单方法:

curl https://bootstrap.pypa.io/get-pip.py | python2
pip2 install package-name    

curl https://bootstrap.pypa.io/get-pip.py | python3
pip3 install package-name

Note: please run these commands as root 注意:请以root身份运行这些命令


#4楼

Firstly, you need to install pip for the Python 3 installation that you want. 首先,您需要为所需的Python 3安装安装pip。 Then you run that pip to install packages for that Python version. 然后运行该pip来安装该Python版本的包。

Since you have both pip and python 3 in /usr/bin, I assume they are both installed with a package manager of some sort. 既然你在/ usr / bin中都有pip和python 3,我认为它们都安装了某种包管理器。 That package manager should also have a Python 3 pip. 包管理器也应该有一个Python 3点。 That's the one you should install. 那是你应该安装的那个。

Felix' recommendation of virtualenv is a good one. 菲利克斯对virtualenv的推荐是一个很好的建议。 If you are only testing, or you are doing development, then you shouldn't install the package in the system python. 如果您只是在测试,或者您正在进行开发,那么您不应该在系统python中安装该软件包。 Using virtualenv, or even building your own Pythons for development, is better in those cases. 使用virtualenv,甚至构建自己的Pythons进行开发,在这些情况下更好。

But if you actually do want to install this package in the system python, installing pip for Python 3 is the way to go. 但是,如果其实希望在系统蟒蛇安装该软件包,安装PIP为Python 3是要走的路。


#5楼

If you have pip installed in both pythons, and both are in your path, just use: 如果您在两个pythons中安装了pip,并且两者都在您的路径中,请使用:

$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME

References: 参考文献:

This is a duplicate of question #2812520 这是问题#2812520的重复


#6楼

Ubuntu 12.10+ and Fedora 13+ have a package called python3-pip which will install pip-3.2 (or pip-3.3 , pip-3.4 or pip3 for newer versions) without needing this jumping through hoops. Ubuntu 12.10+和Fedora 13+有一个名为python3-pip的软件包,它将安装pip-3.2 (或pip-3.3pip-3.4pip3用于更新的版本),而不需要跳过这个环节。


I came across this and fixed this without needing the likes of wget or virtualenvs (assuming Ubuntu 12.04): 我遇到了这个,并修复了这个,而不需要像wget或virtualenvs(假设Ubuntu 12.04):

  1. Install package python3-setuptools : run sudo aptitude install python3-setuptools , this will give you the command easy_install3 . 安装包python3-setuptools :运行sudo aptitude install python3-setuptools ,这将为您提供easy_install3命令。
  2. Install pip using Python 3's setuptools: run sudo easy_install3 pip , this will give you the command pip-3.2 like kev's solution. 使用Python 3的setuptools安装pip:运行sudo easy_install3 pip ,这将为你提供命令pip-3.2就像kev的解决方案一样。
  3. Install your PyPI packages: run sudo pip-3.2 install <package> (installing python packages into your base system requires root, of course). 安装你的PyPI包:运行sudo pip-3.2 install <package> (将python包安装到你的基本系统中当然需要root)。
  4. ...
  5. Profit! 利润!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值