How to install python3 version of package via pip on Ubuntu?
Solution 1
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
Solution 2
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
: runsudo aptitude install python3-setuptools
, this will give you the commandeasy_install3
. - Install pip using Python 3's setuptools: run
sudo easy_install3 pip
, this will give you the commandpip-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!
Solution 3
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.
Solution 4
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
Solution 5
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
kev
Simplicity is the ultimate sophistication. — Leonardo Da Vinci less is more The basic problem is actually very complicated. It's amazing that computers only use 0s and 1s. handy tools # download bigfile $ aria2c -c -k1M -{x,j,s}16 --checksum=md5=dccff28314d9ae4ed262cfc6f35e5153 http://mirrors.zju.edu.cn/ubuntu-releases/14.04/ubuntu-14.04-desktop-amd64.iso # backup txt files $ rsync -avzm --include '*/' --include '*.txt' --exclude '*' source/ remote:target/ # transfer file at 100kB/s $ rsync -hP --bwlimit 100 remote:file . # convert json to csv $ jq -r '[.field1,.field2,.field3]|@csv' input.json > output.csv # http proxy $ ncat -v -l --proxy-type http 3128 # convert socks5 to http $ delegate -P8080 SERVER=http SOCKS=1.2.3.4:1080 [email protected] # convert socks5 to http with auth $ delegated -f -P8080 SERVER=http FORWARD=socks://user:[email protected]:1080 [email protected] # zero-padding file names $ rename 's/^\d+/sprintf("%02d", $&)/e' [0-9]* # concat video parts $ printf "file '%s'\n" part*.mp4 | ffmpeg -f concat -i - -c copy all.mp4 # scan raspberry pi $ sudo nmap -n -sP 192.168.1.0/24 -oX - | xmlstarlet sel -t -m '//host[address[contains(@vendor, "Raspberry Pi")]]/address[@addrtype="ipv4"]/@addr' -v . -n | ssh-keyscan -t rsa -f - | sort -u - ~/.ssh/known_hosts -o ~/.ssh/known_hosts # upgrade all outdated python packages $ pip list --outdated | awk '{print $1}' | xargs -tn1 pip install # generate birthday wordlist for aircrack-ng $ dateseq -f '%Y%m%d' 1970-01-01 2019-01-01 > birthday.txt # install python on raspberry pi $ ansible pi --limit pi2 -e ansible_user=alarm --ask-pass --su --ask-su-pass -m raw -a 'pacman -Sy --noconfirm python2' # resize sdcard for raspberry pi $ echo -e 'p\nd\n2\nn\np\n2\n\n\np\nw' | fdisk /dev/mmcblk0 $ reboot $ resize2fs /dev/mmcblk0p2 # authorized key initialization $ sshpass -p xxxxxx ssh-copy-id -o StrictHostKeyChecking=no user@server # open google chrome in full-screen mode $ open -a 'Google Chrome' --args --kiosk https://github.com/ # customized hostname $ curl --resolve 'httpbin:80:23.22.14.18' http://httpbin/headers # add ssh pubkey to multiple servers $ ansible rpi -m authorized_key -a 'user=pi key="ssh-rsa ..."' # brute force attack openwrt $ hydra -l root -P password.list 192.168.1.1 http-form-post '/cgi-bin/luci:luci_username=^USER^&luci_password=^PASS^:S=302 Found' # dump obs-studio events $ websocat -t -u autoreconnect:ws://127.0.0.1:4444 reuse:appendfile:obs.jl
Updated on December 23, 2021Comments
-
kev over 2 years
I have both
python2.7
andpython3.2
installed inUbuntu 12.04
.
The symbolic linkpython
links topython2.7
.When I type:
sudo pip install package-name
It will default install
python2
version ofpackage-name
.Some package supports both
python2
andpython3
.
How to installpython3
version ofpackage-name
viapip
? -
Lennart Regebro almost 12 yearsDoes virtualenv install pip even if you don't have it installed in the main Python 3? If so, then this does solve his problem. Otherwise not.
-
Felix Yan almost 12 yearsYes, virtualenv installs pip.
-
Lennart Regebro almost 12 yearsOK. I still think the answer doesn't really answer his question in a generic way, though.
-
KomodoDave over 11 yearsPerfect and proper, this should be the accepted answer. However you should specify
sudo pip-3.2 install <package>
, superuser permissions are required. -
jarondl over 11 yearsI find it better to use
--user
to install in~.local/
, than to use sudo. see pep 370 -
chobok over 11 yearsDoing this in Ubuntu 12.04 leaves me with pip-3.2 and pip both installing to the Python 3 directory, with no pip-2.7 available. I had to update pip for Python 2 to resolve both issues.
-
Shashank Bharadwaj over 11 yearsYou can combine steps 1 and 2 and just do:
sudo apt-get install python3-pip
-
akaIDIOT over 11 yearspackages.ubuntu.com shows this super handy package for Ubuntu 12.10, but not for 12.04: packages.ubuntu.com/… (great find though ;))
-
Jacob Wan about 11 yearsvirtualenv itself can be installed via pip to get the latest in older versions of Ubuntu: sudo pip install virtualenv
-
Jacob Wan about 11 yearsThis has the advantage of providing the latest version of both virtualenv and the pip that it provides to virtual environments.
-
papirrin over 10 yearsIn Ubuntu 13.04 and others, pip-3.3 is the current command. Maybe the answer should be updated?
-
akaIDIOT over 10 years@papirrin for recent Ubuntus that's true indeed, though the package
python3-pip
is a lot easier than going througheasy_install3
. I'll add a disclaimer to the answer. -
user2503795 over 10 yearsThis works for me. Two additions: You can leave the
virtualenv
withdeactivate
and python3 might be installed at a different location. Mine is at/usr/local/bin/python3
, which you can find out withwhich python3
-
Adam Ryczkowski almost 10 yearsWorks on Ubuntu 14.04
-
danorton over 9 yearsAlso available in Debian 7.7 (wheezy).
-
6005 about 9 yearspip-3.3, pip-3.4 etc no longer work. It is now just: pip, pip2, pip3. (At least on Ubuntu 14.04)
-
repzero over 8 yearsthis solution also works on debian wheezy and kali linux
-
Yibo Yang over 8 yearsAs of today, I believe apt-get gives you the outdated 1.5.6 version; if you don't want an AssertionErrror during
pip freeze > requirements
(or other potential bugs), do install from source for the latest version and save yourself some headache. -
icedwater over 8 yearsI'm still on Ubuntu 12.04, and I don't get
pip-3.2
either. I havepip3.5
but it doesn't really install Python 3 stuff. It complains that (the Python 2 version of)pandas
is already installed. -
icedwater over 8 yearsThe
curl
call borks for me with a syntax error on line 48. -
Skippy le Grand Gourou about 8 yearsThough Fedora has a
python3-pip
package, it does not create apip3
orpip-3
command as suggested in other answers. This answer indeed works. -
samstav about 8 yearsFollowing @LennartRegebro and @user2503795, I can confirm that this is a bit more robust:
virtualenv -p `which python3` py3env
-
Shirish Kadam almost 8 yearsWorks on Ubuntu 16.04
-
Marco Sulla over 7 years@icedwater: can't help if you don't post the trace (use pastebin).
-
icedwater over 7 yearsThanks @MarcoSulla, but I just re-ran this and noticed a
UserWarning: Support for Python 3.0-3.2 has been dropped. Future versions will fail here.
The paste is at ix.io/1fX5 for all interested parties :) -
user1251007 over 7 yearsA
syntax error
might occur when using a version of python that is no longer supported bypip
. The above commands do work with python3.5 -
Marco Sulla over 7 yearsI added a link to supported versions (currently: 2.6, 2.7, 3.3, 3.4, 3.5)
-
Albert over 7 yearspip>=8 does not work with Python 3.2. So you would need to do
/usr/bin/easy_install3 --user "pip<8"
. -
BrainSlugs83 over 7 yearsGetting all kinds of access denied errors on Ubuntu. -- Tried sudo, still doesn't work.
-
Pynchia about 7 yearsif pip is installed already and it still doesn't work, I recommend to
sudo apt-get purge python3-pip
first -
Gabriel about 7 yearsThis works great, but it assumes that
pip
has already been installed via:sudo apt-get install python3-pip
-
Billal Begueradj almost 7 yearsThis will work on all Ubuntu versions starting from 12.04
-
hynekcer almost 7 yearsYour answer is a duplicate to many answers on this page. (Search "pip3" in text) I don't see any added value of this.
-
Vitalii Dmitriev over 6 yearsFYI: Instead of using
sudo pip3 install MODULE
you can do and better dopip3 install MODULE --user
-
n.caillou about 6 yearsThis answer is outdated.
-
vineeshvs almost 5 yearsIs it equivalent to
python3 -m pip install <package_name>
without virtual environment? -
jbo5112 almost 5 yearsDoesn't work with my Ubuntu 18.04 based system. The package
python3-setuptools
does not give meeasy_install3
. -
akaIDIOT almost 5 years@jbo5112 as per the note above the answer, for newer versions
sudo apt install python3-pip
is the easier option.