4

On Ubuntu 12.04 64-bit, I installed python 2.7.3, and numpy 1.6.2.

When I try to import numpy, I get this:

erelsgl@erel-biu:/host/Dropbox/ai/routes$ python
Python 2.7.3 (default, Nov 25 2012, 17:50:36) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
ImportError: No module named multiarray

Strangely, this problem does not occur on my other computer, which also runs Ubuntu 12.04 64-bit.

UPDATE: I removed the manual installation of numpy:

$ sudo rm -rf /usr/local/lib/python2.7/site-packages/numpy

Then re-installed using apt:

$ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libblas3gf libgfortran3 liblapack3gf
Suggested packages:
  python-numpy-doc python-numpy-dbg python-nose python-dev gfortran
The following NEW packages will be installed:
  libblas3gf libgfortran3 liblapack3gf python-numpy
0 upgraded, 4 newly installed, 0 to remove and 115 not upgraded.
Need to get 6,918 kB of archives.
After this operation, 19.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://il.archive.ubuntu.com/ubuntu/ precise/main libgfortran3 amd64 4.6.3-1ubuntu5 [357 kB]
Get:2 http://il.archive.ubuntu.com/ubuntu/ precise/main libblas3gf amd64 1.2.20110419-2ubuntu1 [287 kB]
Get:3 http://il.archive.ubuntu.com/ubuntu/ precise/main liblapack3gf amd64 3.3.1-1 [4,424 kB]
Get:4 http://il.archive.ubuntu.com/ubuntu/ precise/main python-numpy amd64 1:1.6.1-6ubuntu1 [1,850 kB]
Fetched 6,918 kB in 0s (8,638 kB/s)     
Preconfiguring packages ...
Selecting previously unselected package libgfortran3.
(Reading database ... 80%
(Reading database ... 237799 files and directories currently installed.)
Unpacking libgfortran3 (from .../libgfortran3_4.6.3-1ubuntu5_amd64.deb) ...
Selecting previously unselected package libblas3gf.
Unpacking libblas3gf (from .../libblas3gf_1.2.20110419-2ubuntu1_amd64.deb) ...
Selecting previously unselected package liblapack3gf.
Unpacking liblapack3gf (from .../liblapack3gf_3.3.1-1_amd64.deb) ...
Selecting previously unselected package python-numpy.
Unpacking python-numpy (from .../python-numpy_1%3a1.6.1-6ubuntu1_amd64.deb) ...
Processing triggers for man-db ...
Setting up libgfortran3 (4.6.3-1ubuntu5) ...
Setting up libblas3gf (1.2.20110419-2ubuntu1) ...
update-alternatives: using /usr/lib/libblas/libblas.so.3gf to provide /usr/lib/libblas.so.3gf (libblas.so.3gf) in auto mode.
Setting up liblapack3gf (3.3.1-1) ...
update-alternatives: using /usr/lib/lapack/liblapack.so.3gf to provide /usr/lib/liblapack.so.3gf (liblapack.so.3gf) in auto mode.
Setting up python-numpy (1:1.6.1-6ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

Then tried again, and now, numpy is not recognized at all!

$ python
Python 2.7.3 (default, Nov 25 2012, 17:50:36) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy

4 Answers 4

4

I had same problem. I solved it by deleting numpy in dist packages

sudo rm -rf /usr/local/lib/python2.7/dist-packages/numpy

I didn't install it again and it worked. I tried to import numpy and tested, works just fine. I have no idea why this worked for me. (Maybe there was part of numpy installation documents and python checks this folder sooner, you can check in the sys.path .)

1
  • It also works for me, probably because the code checks for numpy and does something else if it doesn't exist.
    – philshem
    Apr 10, 2014 at 15:15
3

The fact that it's in /usr/local/lib means that you've attempted to install numpy 'manually', which can be a fiddly process to get right.

The easiest way is to remove /usr/local/lib/python2.7/site-packages/numpy, and make sure the package python-numpy is installed (sudo apt-get install python-numpy).

2
  • I did this, and now numpy is not recognized at all - see my update Dec 23, 2012 at 8:04
  • have you modified $PYTHONPATH at all? Can you see numpy in /usr/lib/python2.7/dist-packages/numpy?
    – Thomas K
    Jan 3, 2013 at 22:34
1

Spent two days on this before I tried importing cv2 in the interpreter. I saw there that there was a problem with numpy. I went hunting around and deleted numpy from the roaming folder:

C:\Users[name]\AppData\Roaming\Python\Python35\site-packages

Restarted PyCharm, it reconfigured itself, and all was good. No reinstall of numpy was necessary as previously, in my case, there must've been a duplicate with a version mismatch.

0

The following fixed it for me

sudo apt-get purge python-numpy
sudo pip uninstall numpy
sudo pip install numpy

I had to do the "sudo pip uninstall numpy" multiple times

You must log in to answer this question.

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