0

...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

3
  • Have you actually tried running /usr/bin/python and then tried the imports? I don't see any indication of that. As for removing those other version, I can you can disable them by e.g. sudo mv /usr/Python-2.7.3 /usr/Python-2.7.3-disabled. If everything then keeps working, sudo rm -r /usr/Python-2.7.3-disabled will really get rid of it.
    – 9769953
    Commented Oct 26, 2012 at 8:48
  • Yes, running /usr/bin/python worked perfectly! Successfully imported numpy. BUT! I still do not understand the way how to manage only one python version, how to use exactly the version i need to run for a program.
    – magnump0
    Commented Oct 28, 2012 at 15:05
  • either remove the other Python installation (or better, move them aside), or make sure that in your PATH, /usr/bin comes before /usr/local/bin and other (bin) directories that contain Python. Your shell picks the first python executable it can find on your PATH. If you don't really know how to do that, you may be better off making that a new question (including listing the contents of your .bashrc, .bash_profile and a few other .bash* files that you can find. Assuming your using bash, which is the default shell on Ubuntu).
    – 9769953
    Commented Oct 29, 2012 at 9:26

3 Answers 3

3

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.

1
  • I've done all steps with only one exception - it didn't see virtualenv.py, so I used a full path. Next installed all needed packages, but still get the same error. I don't understand. making 'pip freeze' shows everything I need already installed.
    – magnump0
    Commented Oct 26, 2012 at 0:20
1

This is probably better asked in a Xubuntu forum, because it is most probably a configuration issue. Is there perhaps more than one version of python installed?

In the python interpreter, type the following code;

import sys
print sys.path

Verify that the numpy directory is installed in one of the directories listed in sys.path.

On my FreeBSD (UNIX-like) system with python 2.7.3, numpy is installed as a subdirectory of /usr/local/lib/python2.7/site-packages/. On windows it is probably C:\Python27\Lib\site-packages\.

If you e.g. also have a python 3.x installed, it could be that numpy et cetera in installed for that python. In that case, look in /usr/local/lib/python3.x/site-packages/ or C:\Python3x\Lib\site-packages\.

0
0

You seem to be using a custom-installed Python 2.7.3 in /usr/local/bin. Using /usr/bin/python, you should be able to import numpy; apt-get installs to /usr but never /usr/local.

2
  • Thank you for response. I've added an update to my post.
    – boldnik
    Commented Oct 24, 2012 at 22:34
  • @boldnik: there's no such thing as a "disabled" Python installation. Type which python to find out which one you're running and change your PATH appropriately if it's not the one you want.
    – Fred Foo
    Commented Oct 24, 2012 at 22:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .