I am tired to try to install numpy and scipy for phyton 2.7.5, I need this version of python because my final goal it's to install class (http://class-code.net/) and montepython (http://montepython.net/).
(I have ubuntu 12.04)
When I tried to import numpy or scipy I get the following error everytime:
$ phyton2.7
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/scipy/__init__.py", line 78, in <module>
from numpy import show_config as show_numpy_config
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
In order to get rid of the error I had tried:
- Satisfy python requirement:
$ sudo apt-get install build-essential python-dev gfortran
- Install with apt-get:
$ sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
- Install requirement with pip:
$ sudo pip install requests
- … and tried to installing with pip:
$ sudo pip install numpy
and$ sudo pip install scipy
- I already have the environment var:
export PYTHONPATH=/usr/lib/python2.7/dist-packages:${PYTHONPATH}
The last time I installed numpy and scipy (in older ubuntu version 10.x) this worked for me. -
sudo sh -c "wget http://python-distribute.org/distribute_setup.py -O- | python"
sudo sh -c "wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py -O- | python"
and then install both of them with pip as in (4)But now it seems that the server of python-distribute.org is down. I got the following error:
http://python-distribute.org/distribute_setup.py Resolving python-distribute.org (python-distribute.org)... failed: Name or service not known. wget: unable to resolve host address `python-distribute.org'
-
I had also tried to install numpy and scipy from synaptic and Ubuntu software center
I had failed in each of this attempts and now I don't know what to do.
Am I missing something?
How can I get numpy and scipy correctly installed for python?
Any idea will be appreciated.
when I do
echo $PYTHONPATH
I get
/usr/lib/python2.7/dist-packages
Best Answer
Ok, lets follow the installation guide:
It says you need python 2.7 (which you already have):
Then it says that you need the numpy package too, version >= 1.4.1:
As you can see, I have available numpy version 1.7.1, so lets proceed to install it:
Now it says that we need cython, lets check if that package is availabe:
We have it, we install it:
Please, do notice that there are other packages that are dependency that are being installed too.
Oddly enough, we also need the scipy module too:
Testing. Open python in a terminal and type the following:
The above, has to be without errors. If something went wrong, go up and read the guide again, you forgot/skiped a step.
Downloading the CLASS sources from their page, go to the directory in the terminal, and untar it and make it:
Here we will wait until is complete. Once this is done, we go to the python directory and start the magic. Without moving from directories run this:
Now we have CLASS installed in our user directory. We should test it!
Everything is nice a cozzy until here.
Now the truth time, download monthypython tarball in your code directory:
In the installation instructions are some notes that aren't relevant in this peculiar case (a new install) but it may be important when you update montepython.
This change is important. You remember where you installed CLASS? Now you should tell Monte Python where is that. In my case it is
/home/braiam/src/class_v2.0.2/class
, yours may be different. You can usefind
to look for it:Well, now I modify the
default.conf
file using whatever you like (I'll use nano) and modify theroot
path, so the complete file will looks like:Save the file and exit.
Test montepython! If everything was ok, you should be able to run
code/MontePython.py --help
in your montepythong directory and everything should run:With this, you have montepython installed and ready to roll!