python&linux pip always try to use python2.7 instead of 3.4

2k views Asked by At

Ask: I can't install or upgrade any lib for python 3.4 because pip, pip3, pip3.4 not working or connected to python2.7.

  1. I tried to set alias python=python3 and use just pip:

    sudo pip install selenium

    Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages

  2. I tried pip3:

    sudo pip3 install selenium

    Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages

  3. I tried pip3.4:

    sudo pip3.4 install selenium

    Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages

  4. I tried to create venv for python3.4:

    volodka@interceptor:/usr/bin$ sudo virtualenv -p /usr/bin/python3.4 python3env Running virtualenv with interpreter /usr/bin/python3.4 Using base prefix '/usr' New python executable in python3env/bin/python3.4 Also creating executable in python3env/bin/python Installing setuptools, pip, wheel...done.

    volodka@interceptor:/usr/bin/python3env/bin$ . activate

    (python3env)volodka@interceptor:/usr/bin/python3env/bin$ sudo pip install selenium Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages

Pip3, pip3.4 in virtualenv also try to install lib for python2.7. What I'm doing wrong?

2

There are 2 answers

3
Vaulstein On

The approach you should take is to install pip for Python 3.4.

You do this in the following way:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.4 get-pip.py

You then install things for Python 3.4 with pip3.4, and you install things with Python 2-7 with pip-2.7.

Check /usr/bin to see which pip versions you have there.

0
Milan_J On

This is perhaps not the best solution. Having the same issue on Fedora 22, I managed to install python3 packages using pip this way:sudo pip3 install --install-option="--prefix=/usr/lib/python3.4/site-packages" package_name