0

I've recently upgraded to use Python 3.6 on Ubuntu 16.04. Now I have Python 2.7, 3.5, and 3.6 all on the same system. I've had pip (defaults to v2.7), and pip3 (defaults to v3.5), and I then reinstalled pip3 according to this link: https://stackoverflow.com/a/44254088/3123703 .

I'm now on the path to installing all the libraries I'm using for the new Python 3.6. But for some reason, pip3.6 is checking for the libraries in Python 3.5 folders:

$ sudo pip3.6 install numpy
Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages

Also:

$ pip3 --version
pip 9.0.1 from /home/<user>/.local/lib/python3.6/site-packages (python 3.6)

$ pip3.6 --version
pip 9.0.1 from /home/<user>/.local/lib/python3.6/site-packages (python 3.6)

Is there a way to get pip3.6 to not look in the Python 3.5 folders? Or do I have to completely uninstall Python 3.5 and Python 3.6 and start from scratch?

FYI, I'm not asking for a specific package, as numpy was just an example here.

0

Highlighting your question:

Is there a way to get pip3.6 to not look in the Python 3.5 folders? Or do I have to completely uninstall Python 3.5 and Python 3.6 and start from scratch?

I recommend not installing several different Python versions on the system level, instead use a dedicated tool for Python. I use Anaconda, which is great for scientific computing. Other tools exist.

How to use a Python installation from your home directory

  • You install the Python version you want to use in a separate directory (for example ~/anaconda3)
  • Add the binary folder from your Python install first in your PATH.

How to handle multiple Python versions with Anaconda

  1. Install Miniconda from https://conda.io/miniconda.html
  2. Make sure conda is availible from your shell by adding the binary install folder to your PATH
  3. Install any Python versions you want. Refer to it later with the -n parameter (python2 or python3 here).
    • Python 2: conda create -n python2 python=2.7 anaconda
    • Python 3: conda create -n python3 python=3.6 anaconda
  4. Switch Python version by sourcing the activate script
    • Python 2: source activate python2
    • Python 3: source activate python3

Example usage

teodorlu@XPS13 ~ % conda env list
# conda environments:
#
python2                  /home/teodorlu/anaconda2/envs/python2
python3                  /home/teodorlu/anaconda2/envs/python3

teodorlu@XPS13 ~ % source activate python2
teodorlu@XPS13 ~ % which python
/home/teodorlu/anaconda2/envs/python2/bin/python
teodorlu@XPS13 ~ % python
Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> np.__file__
'/home/teodorlu/anaconda2/envs/python2/lib/python2.7/site-packages/numpy/__init__.pyc'
>>> 
teodorlu@XPS13 ~ % source activate python3
teodorlu@XPS13 ~ % which python
/home/teodorlu/anaconda2/envs/python3/bin/python
teodorlu@XPS13 ~ % python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__file__
'/home/teodorlu/anaconda2/envs/python3/lib/python3.6/site-packages/numpy/__init__.py'
| improve this answer | |
  • Thanks! I've tried to get this to work for the past hour. It installed quite well, but when running conda create -n python3.6 python=3.6 anaconda --file requirements.txt, conda doesn't appear to be able to find most of the packages. Out of the 10 I've tried, I get the response Package missing in current linux-64 channels: <package name>. This package list comes straight from pip3.5 freeze > requirements.txt because I would like the same packages as in Python 3.5. – nfmcclure Jun 20 '17 at 21:01
  • I'd try to install anaconda 3.5 first, and see if you find the package then. If that doesn't work, you can try Virtualenvs. Anaconda is tailored to scientific Python, whereas Virtualenv is generic. – Teodor Jun 21 '17 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.