How do I use pip 3 with Python 3.4?
Asked Answered
S

3

22

My OS is Lubuntu 14.04 and the default Python version is Python 2.7.6, but in

/usr/bin

it says I have Python 3.4 installed (when I run python3 -V it says I have Python 3.4.0). Does Python 3.4 come with a pre-installed pip? Because when I run

pip -V

in a terminal it says that the program is currently not installed. With that said, assume I want to create a Django project which uses Python 3.4.3: do I first download python3-pip and then virtualenv and then do

pip3 install Django==1.8

? or is there a pre-installed pip 3 which comes with Python 3.4 which I already have installed?

Singhalese answered 18/4, 2015 at 3:22 Comment(0)
E
40

Instead of installing python3-pip via apt-get or whatever (because the version in the repo is too old), download get-pip.py, switch to the folder where you saved it, and run

sudo python3 get-pip.py

and it will install the latest version of pip for you. It may create a symlink to pip3, it may not, I don't remember.

You can then run

sudo pip install virtualenv

then use it to create your virtualenv, activate it, then use the pip installed inside it to get Django.

NOTE:

You can use the same copy of get-pip.py to install pip for Python 2. If you want to do that, however, I'd advise you to run

sudo python get-pip.py

before you run

sudo python3 get-pip.py

Whichever one you install last will take the pip filename. I don't know if Python 2 installs a command called pip2 (I know upgrading pip via pip does), but after you run the Python 2 install, run

sudo ln -s /usr/local/bin/pip2.7 /usr/local/bin/pip2

to create a pip2 alias. You can then run the Python 3 install, which will overwrite /usr/local/bin/pip, then run

sudo ln -s /usr/local/bin/pip3.4 /usr/local/bin/pip3

to create a pip3 command as well (if you get an error that the file already exists, then you're good to go). Now, instead of running pip when installing to your system site-packages and not knowing exactly which version you're calling, you can just use pip2 and pip3 to explicitly state the version you want.

Exert answered 18/4, 2015 at 3:53 Comment(2)
It may be worth mentioning that python3.4 should always ship pip by default. So python3 -m pip should work out of the box. If not, there's python -m ensurepip to bootstrap pip. get-pip.py should not be necessary here.Hild
@cel, yes, thank you for that clarification. The reason I chose get-pip.py was because I wasn't sure if Ubuntu and derivatives automatically install pip with the python3 packages, as there also exists a python3-pip package. My system is so customized now that I don't remember what it was like when I first installed :) The other reason to use get-pip.py is that it also updates setuptools, which may not otherwise be done.Exert
C
7

In previous (X)Ubuntu versions it would be found under pip3 in your bash terminal, but such command didn't appear for me in Xubuntu 16.04.1 LTS. I founded pip (version python2.7), pip2 and pip2.7.

You know pip is in the repositories under python3-pip. If you want to use pip in the repo firstly you must have it installed. Answering your question,

How to use pip3 in Ubuntu:

sudo python3 -m pip install <your-pypi>

Maybe for you is easier to have pip3 as a command. Then, you need to upgrade it:

sudo python3 -m pip install --upgrade pip

It will create pip3 and pip3.5 **but** it modifies pip too. It did for me, now if I do pip -V it shows (python 3.5). Maybe this replacement is the reason Ubuntu doesn't include the pip3 binaries as commands.

Update June 2019:

I'm using Ubuntu 18.04.x LTS since last year. I founded locally installed (in ~/.local) pip command pointing to pip2 (like python always points to python2) and pip3 pointing my last version of pip for python3.x as expected. So it is safe to install the package python3-pip from the repo. Although python2 was installed at system level at the beginning, it did not include pip or pip2 command in /usr/bin/

Champignon answered 24/12, 2016 at 5:6 Comment(0)
U
1

I have python 3.4.2 installed on a debian derived OS (bunsenlabs hydrogen) and I spent many hours trying to resolve the problem before finding this thread. Using get-pip.py worked for me, but not quite as shown in this thread. Below is the order that worked for me. BTW, before running this I had to run:

apt-get remove python3-pip

because a different thread had suggested installing 'python3-pip'. That package gave me pip, but I then received errors that 'ensurepip' was missing.

Here is my sequence that worked:

1) download get-pip.py using the instruction given by MattDMo above
2) sudo python3 get-pip.py
3) sudo python3 -m pip install virtualenv
4) as normal user:
    % cd $HOME
    % mkdir testenv
    % python3 -m virtualenv testenv

My thanks to MattDMo for providing an explanation of what works.

Urease answered 18/12, 2016 at 14:21 Comment(2)
Why are you uninstalling pip just to install it again?Gredel
Kind of like cleaning the floor before putting in a new carpet. I did not know if the existing installation of python3-pip would contaminate my next steps.Urease

© 2022 - 2024 — McMap. All rights reserved.