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
?
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:
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.
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.
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 viapython3
, so knowing the pip package origin, I just downloaded it and issuedsudo 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.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:
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
orpython-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.or
With Python 2.4+ you can invoke
easy_install
with specific Python version by usingpython -m easy_install
. Sopip
for Python 3 could be installed by:That's it, you got
pip
for Python 3. Now just invokepip
with the specific version of Python to install package for Python 3. For example, with Python 3.2 installed on my system, I used:Ubuntu 12.10+ and Fedora 13+ have a package called
python3-pip
which will installpip-3.2
(orpip-3.3
,pip-3.4
orpip3
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):python3-setuptools
: runsudo aptitude install python3-setuptools
, this will give you the commandeasy_install3
.sudo easy_install3 pip
, this will give you the commandpip-3.2
like kev's solution.sudo pip-3.2 install <package>
(installing python packages into your base system requires root, of course).