Install python2.7.3 + numpy + scipy + matplotlib + scikits.statsmodels + pandas0.7.3 correctly

matplotlibpython

…using Linux (xubuntu).
How to install python2.7.3 + numpy + scipy + matplotlib + scikits.statsmodels + pandas0.7.3 correctly ? My final aim is to have them working. The problem:

~$ python --version
Python 2.7.3

so i already have a system-default 2.7.3, which is good!

~$ dpkg -s python-numpy
Package: python-numpy
Status: install ok installed

and i already have numpy installed! great! But…

~$ python
Python 2.7.3 (default, Oct 23 2012, 01:07:38) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as nmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

this module couldn't be find by python. The same with scipy, matplotlib. Why?

~$ sudo apt-get install python-numpy
[...] 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-numpy is already the newest version.
[...]

why it does not see numpy and others ?

update:

>>> import sys
>>> print sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
>>> 

so i do have /usr/local/lib/python2.7

~$ pip freeze
Warning: cannot find svn location for distribute==0.6.16dev-r0
BzrTools==2.4.0
CDApplet==1.0
[...]
matplotlib==1.0.1
mutagen==1.19
numpy==1.5.1
[...]
pandas==0.7.3
papyon==0.5.5
[...]
pytz==2012g
pyxdg==0.19
reportlab==2.5
scikits.statsmodels==0.3.1
scipy==0.11.0
[...]
zope.interface==3.6.1

as you can see, those modules are already installed! But! ls -la /usr/local/lib/ gives ONLY python2.7 dir. And still

~$ python -V
Python 2.7.3

and

import sys
sys.version
'2.7.3 (default, Oct 23 2012, 01:07:38) \n[GCC 4.6.1]'

updated:

Probably I've missed another instance… One at /usr/Python-2.7.3/ and second (seems to be installed "by hands" far far ago) at /usr/python2.7.3/Python-2.7.3/
But how two identical versions can work at the same time??? Probably, one of them is "disabled" (not used by any program, but I don't know how to check if any program uses it).

~$ ls -la /usr/bin/python*
lrwxrwxrwx 1 root root       9 2011-11-01 11:11 /usr/bin/python -> python2.7
-rwxr-xr-x 1 root root 2476800 2012-09-28 19:48 /usr/bin/python2.6
-rwxr-xr-x 1 root root    1452 2012-09-28 19:45 /usr/bin/python2.6-config
-rwxr-xr-x 1 root root 2586060 2012-07-21 01:42 /usr/bin/python2.7
-rwxr-xr-x 1 root root    1652 2012-07-21 01:40 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root       9 2011-10-05 23:53 /usr/bin/python3 -> python3.2
lrwxrwxrwx 1 root root      11 2011-09-06 02:04 /usr/bin/python3.2 -> python3.2mu
-rwxr-xr-x 1 root root 2852896 2011-09-06 02:04 /usr/bin/python3.2mu
lrwxrwxrwx 1 root root      16 2011-10-08 19:50 /usr/bin/python-config -> python2.7-config

there is a symlink python->python2.7, maybe I can ln -f -s this link to exact /usr/Python-2.7.3/python destination without harm ?? And how correctly to remove the 'copy' of 2.7.3?
And else…

~$ ls -la /usr/bin/virtualenv 
-rwxr-xr-x 1 root root 58 2011-03-16 18:55 /usr/bin/virtualenv

but works only in this case:

~$ /usr/bin/python /usr/bin/virtualenv qenv
New python executable in qenv/bin/python
Installing distribute....................................................................................................................................................................................done.
Installing pip...............done.

and this doesn't work!

 python virtualenv.py pyenv

I will try to be more clear. Just questions. Why I can import numpy starting '/usr/bin/python' but can not by using only 'python'? If I want to install another version of python for different applications, what is the best way to do this? How to install packages into chosen pythonpath? I did not find a complete guide.


Thanks to everyone!
Solved it this way:

$ sudo nano /usr/share/python/debian_defaults
$ sudo mv /usr/bin/python /usr/bin/python2.Y_old
$ sudo ln -s -f /usr/bin/python2.7 /usr/bin/python

My default version was 2.7.3 and now it's 2.7.2+. I do not see huge difference, so I think it was quite safe. But I need to read more about

virtualenv

and

pip
and default
PATH

Best Answer

I strongly recomend you to use virtualenv. Virtualenv allows you to create python environment in per project basis. My workflow to begin a new project is

  • Create the project directory myapp
  • Download virtualenv from https://github.com/pypa/virtualenv/tarball/develop
  • Create a virtual environment: python virtualenv.py pyenv
  • Activate the virtualenv source pyenv/bin/activate
  • Install the packages in the virtual environment:

    pip install -U numpy matplotlib pandas ...

With this setup, you can control the version, reinstall or remove the packages without have to depend on the version that is available in the repositories.