问题:如何在Ubuntu上通过pip安装python3版本的软件包?
我都python2.7
和python3.2
安装Ubuntu 12.04
。
符号链接python
链接到python2.7
。
当我输入:
sudo pip install package-name
它将默认安装的python2
版本package-name
。
一些软件包同时支持python2
和python3
。
如何安装via python3
版本?package-name
pip
I have both python2.7
and python3.2
installed in Ubuntu 12.04
.
The symbolic link python
links to python2.7
.
When I type:
sudo pip install package-name
It will default install python2
version of package-name
.
Some package supports both python2
and python3
.
How to install python3
version of package-name
via pip
?
回答 0
您可能需要构建virtualenv
python3的,然后在激活virtualenv之后安装python3的软件包。这样您的系统就不会混乱了:)
可能是这样的:
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install package-name
You may want to build a virtualenv
of python3, then install packages of python3 after activating the virtualenv. 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
回答 1
Ubuntu 12.10+和Fedora 13+都有一个名为的软件包python3-pip
,它将安装pip-3.2
(或pip-3.3
,pip-3.4
或者pip3
对于较新的版本),而无需花钱。
我碰到了这一点,并在不需要like wget
或virtualenvs的情况下解决了这个问题(假设Ubuntu 12.04):
- 安装软件包
python3-setuptools
:运行sudo aptitude install python3-setuptools
,这将给您命令easy_install3
。 - 使用Python 3的setuptools安装run pip:run
sudo easy_install3 pip
,这将为您提供pip-3.2
类似于kev解决方案的命令。 - 安装您的PyPI软件包:运行
sudo pip-3.2 install <package>
(将python软件包安装到基本系统中当然需要root)。 - …
- 利润!
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.
I came across this and fixed this without needing the likes of wget
or virtualenvs (assuming Ubuntu 12.04):
- Install package
python3-setuptools
: run sudo aptitude install python3-setuptools
, this will give you the command easy_install3
. - 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. - Install your PyPI packages: run
sudo pip-3.2 install <package>
(installing python packages into your base system requires root, of course). - …
- Profit!
回答 2
简短答案
sudo apt-get install python3-pip
sudo pip3 install MODULE_NAME
资料来源:Shashank Bharadwaj的评论
长答案
简短的答案仅适用于较新的系统。在某些版本的Ubuntu上,命令为pip-3.2
:
sudo pip-3.2 install MODULE_NAME
如果不起作用,则此方法适用于任何Linux发行版和受支持的版本:
sudo apt-get install curl
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
sudo pip3 install MODULE_NAME
如果没有curl
,请使用wget
。如果没有sudo
,请切换到root
。如果pip3
symlink不存在,请检查类似pip-3的内容。X
许多python软件包也需要dev软件包,因此也要安装它:
sudo apt-get install python3-dev
来源:
python使用pip安装软件包
Pip最新安装
如果您想要更高版本的Python,也请查看Tobu的答案。
我想补充一点,使用虚拟环境通常是开发python应用程序的首选方法,因此@felixyan答案可能是理想世界中的最佳选择。但是,如果您真的想在全球范围内安装该软件包,或者需要在不激活虚拟环境的情况下频繁测试/使用该软件包,那么我认为将其作为全局软件包安装是可行的方法。
Short Answer
sudo apt-get install python3-pip
sudo pip3 install MODULE_NAME
Source: Shashank Bharadwaj’s comment
Long Answer
The short answer applies only on newer systems. On some versions of Ubuntu the command is pip-3.2
:
sudo pip-3.2 install MODULE_NAME
If it doesn’t work, this method should work for any Linux distro and supported version:
sudo apt-get install curl
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
sudo pip3 install MODULE_NAME
If you don’t have curl
, use wget
. If you don’t have sudo
, switch to root
. If pip3
symlink does not exists, check for something like pip-3.X
Much python packages require also the dev package, so install it too:
sudo apt-get install python3-dev
Sources:
python installing packages with pip
Pip latest install
Check also Tobu’s answer if you want an even more upgraded version of Python.
I want to add that using a virtual environment is usually the preferred way to develop a python application, so @felixyan answer is probably the best in an ideal world. But if you really want to install that package globally, or if need to test / use it frequently without activating a virtual environment, I suppose installing it as a global package is the way to go.
回答 3
好吧,在ubuntu 13.10 / 14.04上,情况有所不同。
安装
$ sudo apt-get install python3-pip
安装套件
$ sudo pip3 install packagename
不 pip-3.3 install
Well, on ubuntu 13.10/14.04, things are a little different.
Install
$ sudo apt-get install python3-pip
Install packages
$ sudo pip3 install packagename
NOT pip-3.3 install
回答 4
安装最新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
注意:请按以下方式运行这些命令root
The easiest way to install latest pip2
/pip3
and corresponding packages:
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
回答 5
尝试安装pylab时遇到了同样的问题,并且找到了此链接
因此,我在Python 3中安装pylab所做的工作是:
python3 -m pip install SomePackage
它运行正常,并且如您在链接中所见,您可以为每个Python版本执行此操作,因此我想这可以解决您的问题。
I had the same problem while trying to install pylab, and I have found this link
So what I have done to install pylab within Python 3 is:
python3 -m pip install SomePackage
It has worked properly, and as you can see in the link you can do this for every Python version you have, so I guess this solves your problem.
回答 6
旧的问题,但没有一个答案令我满意。我的系统之一正在运行Ubuntu 12.04 LTS,由于某种原因,没有软件包python3-pip
或python-pip
Python3。所以这就是我所做的(所有命令均以root用户身份执行):
setuptools
如果没有,请安装Python3。
apt-get install python3-setuptools
要么
aptitude install python3-setuptools
在Python 2.4+中,您可以使用调用easy_install
特定的Python版本python -m easy_install
。因此,pip
对于Python 3,可以通过以下方式安装:
python3 -m easy_install pip
就是这样,您使用的是pip
Python3。现在只需调用pip
特定版本的Python即可安装Python 3的软件包。例如,在系统上安装了Python 3.2的情况下,我使用了:
pip-3.2 install [package]
Old question, but none of the answers satisfies me. One of my systems is running Ubuntu 12.04 LTS and for some reason there’s no package python3-pip
or python-pip
for Python 3. So here is what I’ve done (all commands were executed as root):
Install setuptools
for Python3 in case you haven’t.
apt-get install python3-setuptools
or
aptitude install python3-setuptools
With Python 2.4+ you can invoke easy_install
with specific Python version by using python -m easy_install
. So pip
for Python 3 could be installed by:
python3 -m easy_install pip
That’s it, you got pip
for Python 3. Now just invoke pip
with the specific version of Python to install package for Python 3. For example, with Python 3.2 installed on my system, I used:
pip-3.2 install [package]
回答 7
如果您在两个python中都安装了pip,并且都在路径中,则只需使用:
$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME
参考文献:
这是问题的重复#2812520
If you have pip installed in both pythons, and both are in your path, just use:
$ pip-2.7 install PACKAGENAME
$ pip-3.2 install PACKAGENAME
References:
This is a duplicate of question #2812520
回答 8
如果您的系统python2
是默认设置,请使用以下命令将软件包安装到python3
$ python3 -m pip install <package-name>
If your system has python2
as default, use below command to install packages to python3
$ python3 -m pip install <package-name>
回答 9
很简单:
sudo aptitude install python3-pip
pip-3.2 install --user pkg
如果要使用Python 3.3(自Ubuntu 12.10起不是默认设置):
sudo aptitude install python3-pip python3.3
python3.3 -m pip.runner install --user pkg
Easy enough:
sudo aptitude install python3-pip
pip-3.2 install --user pkg
If you want Python 3.3, which isn’t the default as of Ubuntu 12.10:
sudo aptitude install python3-pip python3.3
python3.3 -m pip.runner install --user pkg
回答 10
您也可以直接运行pip3 install packagename
,而不是pip
,
You can alternatively just run pip3 install packagename
instead of pip
,
回答 11
首先,您需要为想要的Python 3安装安装pip。然后,您运行该pip为该Python版本安装软件包。
由于您在/ usr / bin中同时拥有pip和python 3,因此我假定它们都已通过某种程序包管理器安装。该软件包管理器还应具有Python 3点。那是您应该安装的那个。
Felix对virtualenv的推荐是一个很好的建议。如果您只是测试,或者正在开发,则不应将软件包安装在系统python中。在这些情况下,使用virtualenv甚至构建自己的Python进行开发会更好。
但如果你真的不希望在系统Python安装该软件包,为Python 3安装PIP是要走的路。
Firstly, you need to install pip for the Python 3 installation that you want. Then you run that pip to install packages for that Python version.
Since you have both pip and python 3 in /usr/bin, I assume they are both installed with a package manager of some sort. That package manager should also have a Python 3 pip. That’s the one you should install.
Felix’ recommendation of virtualenv is a good one. If you are only testing, or you are doing development, then you shouldn’t install the package in the system python. Using virtualenv, or even building your own Pythons for development, is better in those cases.
But if you actually do want to install this package in the system python, installing pip for Python 3 is the way to go.
回答 12
尽管该问题与Ubuntu有关,但我还是要说我在Mac上,而我的python
命令默认为Python 2.7.5。我也有Python 3,可通过进行访问python3
,因此知道了pip包的起源,我就下载了pip包并sudo python3 setup.py install
针对它发布了,当然,只有Python 3现在在其站点包中包含了此模块。希望这有助于流浪的Mac陌生人。
Although the question relates to Ubuntu, let me contribute by saying that I’m on Mac and my python
command defaults to Python 2.7.5. I have Python 3 as well, accessible via python3
, so knowing the pip package origin, I just downloaded it and issued sudo python3 setup.py install
against it and, surely enough, only Python 3 has now this module inside its site packages. Hope this helps a wandering Mac-stranger.
回答 13
直接执行pip二进制文件。
首先找到所需的PIP版本。
jon-mint python3.3 # whereis ip
ip: /bin/ip /sbin/ip /usr/share/man/man8/ip.8.gz /usr/share/man/man7/ip.7.gz
然后执行。
jon-mint python3.3 # pip3.3 install pexpect
Downloading/unpacking pexpect
Downloading pexpect-3.2.tar.gz (131kB): 131kB downloaded
Running setup.py (path:/tmp/pip_build_root/pexpect/setup.py) egg_info for package pexpect
Installing collected packages: pexpect
Running setup.py install for pexpect
Successfully installed pexpect
Cleaning up...
Execute the pip binary directly.
First locate the version of PIP you want.
jon-mint python3.3 # whereis ip
ip: /bin/ip /sbin/ip /usr/share/man/man8/ip.8.gz /usr/share/man/man7/ip.7.gz
Then execute.
jon-mint python3.3 # pip3.3 install pexpect
Downloading/unpacking pexpect
Downloading pexpect-3.2.tar.gz (131kB): 131kB downloaded
Running setup.py (path:/tmp/pip_build_root/pexpect/setup.py) egg_info for package pexpect
Installing collected packages: pexpect
Running setup.py install for pexpect
Successfully installed pexpect
Cleaning up...
回答 14
您应该安装所有依赖项:
sudo apt-get install build-essential python3-dev python3-setuptools python3-numpy python3-scipy libatlas-dev libatlas3gf-base
安装pip3(如果已安装,请查看步骤3):
sudo apt-get install python3-pip
我通过pip3安装scikit-learn
pip3 install -U scikit-learn
打开您的终端并输入python3环境,键入import sklearn
以进行检查。
祝你好运!
You should install ALL dependencies:
sudo apt-get install build-essential python3-dev python3-setuptools python3-numpy python3-scipy libatlas-dev libatlas3gf-base
Install pip3(if you have installed, please look step 3):
sudo apt-get install python3-pip
Iinstall scikit-learn by pip3
pip3 install -U scikit-learn
Open your terminal and entry python3 environment, type import sklearn
to check it.
Gook Luck!
回答 15
要为python3安装pip,请使用pip3而不是pip。在Ubuntu 18.08 Bionic中安装python
须藤apt-get install python3.7
在ubuntu中安装所需的pip软件包
须藤apt-get install python3-pip
To install pip for python3 use should use pip3 instead of pip. To install python in ubuntu 18.08 bionic
sudo apt-get install python3.7
To install the required pip package in ubuntu
sudo apt-get install python3-pip
回答 16
安装python3的另一种方法是使用wget。以下是安装步骤。
wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install
另外,可以使用
echo 'alias py="/opt/python3.3/bin/python3.3"' >> ~/.bashrc
现在打开一个新终端并输入py并按Enter。
Another way to install python3 is using wget. Below are the steps for installation.
wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd ./Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install
Also,one can create an alias for the same using
echo 'alias py="/opt/python3.3/bin/python3.3"' >> ~/.bashrc
Now open a new terminal and type py and press Enter.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。