-2

I am running Linux Ubuntu 16.04 LTS. I installed pip in order to load third party packages for Python. Python 2.7 and 3.5.2 came with my Linux distro, but I installed 3.6 later. Now I am trying to install Scipy. Following the instructions for Scipy stack installation at scipy.org, I ran the following command (after previous pip install) in the terminal:

pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

The problem is this only installs the packages for Python 2.7, not 3.5.2 or 3.6. How do I get the installations to work for Python 3.x? Guidance is much appreciated. My hair is going gray over this and I can't seem to get the right results by Googling.

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
  • 1
    Have you looked into installing pip for python3: `sudo apt-get install python3-pip` and then using `pip3` (instead of `pip`) to install your packages? – Akavall Feb 18 '17 at 22:48
  • 1
    I would recommend looking into [virtualenv](https://virtualenv.pypa.io/en/stable/) or using [Anaconda](https://www.continuum.io/downloads) and creating environments for your different versions of python – Grr Feb 18 '17 at 23:22

2 Answers2

2

May I recommend Anaconda? https://www.continuum.io/

Anaconda (a.k.a. Conda) is a cross-platform package manager that supports Windows, Mac and Linux. It was designed to solve the problems with other package managers (e.g. easy-install, pip, distutils).

Conda solves a lot of problems with packaging. After installing Conda, you can install your desired packages without fear of them failing. You can also create "virtual environments". You want Python2 and Python3 on the same system? Done.

conda create -n Python2 python=2.7.13
conda create -n Python3 python=3.6.0

To switch to one, you would type:

activate Python2

Now you're in the Python2 environment.

You can call the environments whatever you'd like.

Here's a very useful 20 minute video of Aaron Meurer from Continuum giving a presentation on Conda at SciPy 2014. (https://www.youtube.com/watch?v=UaIvrDWrIWM) I watched this video and it changed my life forever (regarding Python environments and packaging).

With Conda, to create SciPy2 and SciPy3 environments:

>conda search scipy
Fetching package metadata ...........
scipy                        0.11.0               np17py27_1  defaults
                             0.11.0               np16py27_1  defaults
                             0.11.0               np17py26_1  defaults
                             0.11.0               np16py26_1  defaults
                             0.12.0               np17py26_0  defaults
                             0.12.0               np17py33_0  defaults
                             0.12.0               np17py27_0  defaults
                             0.12.0              np16py27_p0  defaults        [mkl]
                             0.12.0              np17py27_p0  defaults        [mkl]
                                        << Truncated >>
                             0.18.0              np111py34_0  defaults
                             0.18.0              np111py35_0  defaults
                             0.18.0              np111py27_0  defaults
                             0.18.1              np111py35_0  defaults
                             0.18.1              np111py27_0  defaults
                             0.18.1              np111py36_0  defaults
                             0.18.1              np111py34_0  defaults
                             0.18.1              np112py27_1  defaults
                             0.18.1              np111py34_1  defaults
                             0.18.1              np112py36_1  defaults
                             0.18.1              np111py36_1  defaults
                             0.18.1              np112py35_1  defaults
                          *  0.18.1              np111py27_1  defaults
                             0.18.1              np111py35_1  defaults

>conda search python
Fetching package metadata ...........
python                       2.6.8                         5  defaults
                             2.6.8                         6  defaults
                             2.6.9                         0  defaults
                             2.6.9                         1  defaults
                             2.7.3                         2  defaults
                                        << Truncated >>
                             2.7.10                        0  defaults
                             2.7.10                        1  defaults
                             2.7.10                        3  defaults
                             2.7.10                        4  defaults
                             2.7.10                        5  defaults
                             2.7.11                        0  defaults
                             2.7.11                        1  defaults
                             2.7.11                        2  defaults
                             2.7.11                        4  defaults
                             2.7.11                        5  defaults
                             2.7.12                        0  defaults
                          *  2.7.13                        0  defaults
                             3.3.0                         4  defaults
                             3.3.1                         0  defaults
                             3.3.2                         0  defaults
                             3.3.3                         0  defaults
                             3.3.4                         0  defaults
                             3.3.5                         0  defaults
                                        << Truncated >>
                             3.5.1                         0  defaults
                             3.5.1                         1  defaults
                             3.5.1                         2  defaults
                             3.5.1                         4  defaults
                             3.5.1                         5  defaults
                             3.5.2                         0  defaults
                             3.6.0                         0  defaults

>conda create -n SciPy2 python=2.7.13 scipy=0.18.1
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment D:\Applications\Anaconda\envs\SciPy2:

The following NEW packages will be INSTALLED:

    mkl:            2017.0.1-0
    numpy:          1.12.0-py27_0
    pip:            9.0.1-py27_1
    python:         2.7.13-0
    scipy:          0.18.1-np112py27_1
    setuptools:     27.2.0-py27_1
    vs2008_runtime: 9.00.30729.5054-0
    wheel:          0.29.0-py27_0

Proceed ([y]/n)? y

numpy-1.12.0-p 100% |###############################| Time: 0:00:00  10.88 MB/s
scipy-0.18.1-n 100% |###############################| Time: 0:00:00  13.49 MB/s
#
# To activate this environment, use:
# > activate SciPy2
#
# To deactivate this environment, use:
# > deactivate SciPy2
#
# * for power-users using bash, you must source
#


>conda create -n SciPy3 python=3.6.0 scipy=0.18.1
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment D:\Applications\Anaconda\envs\SciPy3:

The following NEW packages will be INSTALLED:

    mkl:            2017.0.1-0
    numpy:          1.12.0-py36_0
    pip:            9.0.1-py36_1
    python:         3.6.0-0
    scipy:          0.18.1-np112py36_1
    setuptools:     27.2.0-py36_1
    vs2015_runtime: 14.0.25123-0
    wheel:          0.29.0-py36_0

Proceed ([y]/n)? y

vs2015_runtime 100% |###############################| Time: 0:00:00   9.96 MB/s
python-3.6.0-0 100% |###############################| Time: 0:00:02  12.86 MB/s
numpy-1.12.0-p 100% |###############################| Time: 0:00:00  13.61 MB/s
setuptools-27. 100% |###############################| Time: 0:00:00  13.15 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00  18.89 MB/s
pip-9.0.1-py36 100% |###############################| Time: 0:00:00  11.73 MB/s
scipy-0.18.1-n 100% |###############################| Time: 0:00:00  12.76 MB/s
#
# To activate this environment, use:
# > activate SciPy3
#
# To deactivate this environment, use:
# > deactivate SciPy3
#
# * for power-users using bash, you must source
#


>activate SciPy3

(SciPy3) >

Note: I just did this on Windows. It works the same on Mac and Linux, except like it says, using Bash you have to source before you can activate.

I hope this helps you as it has helped me.

Damian T.
  • 321
  • 1
  • 10
2

As mentioned by @Akavall, at the moment you have installed a Python2.x pip and it is this pip that you are currently using to install packages when you run this command pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose. For you to install packages for Python3.x, you will need to install a Python3.x pip which is referenced as pip3. To install pip3, run the following command from your terminal:

sudo apt-get install python3-pip

Once pip3 has been installed, you can then install packages for your python3.x using:

pip3 install <module-name>

Note that you can still continue to run both Python2.x and Python3.x along side each other on the same machine, there is no need for you to uninstall python2.x.

You can continue to install packages for Python2.x as you have been doing, by using:

pip install <module-name>

and install packages for python3.x using:

pip3 install <module-name>

Lastly, to run Python3.x on your terminal you will need to type:

python3

as opposed to just python (which refers to python2.x). For example, if you have a script called Hello.py, to execute this script from the terminal using Python3.x you do the following:

python3.x Hello.py

to run the same script using Python2.x, you do the following:

python2.x Hello.py

or:

python Hello.py

So, in one sentence, pip points to python2, whist pip3 points to python3. See this question for more information.

I hope that answers your question :). Once again, I'm just expanding on a good comment already given above by @Akavall, so credit goes to @Akavall.

Community
  • 1
  • 1
Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
  • My pleasure, I'm glad I could help :). If the answer does indeed solve your problem, you can mark it as the correct answer - If it does answer your question, that is. – Tshilidzi Mudau Feb 19 '17 at 01:56