web-dev-qa-db-fra.com

import numpy - pas de module nommé multiarray

Sur Ubuntu 12.04 64 bits, j'ai installé python 2.7.3 et numpy 1.6.2.

Lorsque j'essaie d'importer numpy, j'obtiens ceci:

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

Étrangement, ce problème ne se produit pas sur mon autre ordinateur, qui exécute également Ubuntu 12.04 64 bits.

UPDATE: J'ai supprimé l'installation manuelle de numpy:

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

Puis ré-installé en utilisant 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

Puis réessayé, et maintenant, numpy n’est pas reconnu du tout!

$ 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
Erel Segal-Halevi

J'ai eu le même problème. Je l'ai résolu en supprimant numpy dans les paquets dist

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

Je ne l'ai pas réinstallé et cela a fonctionné. J'ai essayé d'importer numpy et testé, fonctionne très bien. Je ne sais pas pourquoi cela a fonctionné pour moi. (Peut-être qu'il y avait une partie des documents d'installation de numpy et que python vérifie ce dossier plus tôt, vous pouvez vérifier le chemin sys.path.)

4
Mojmir

Le fait qu'il soit dans /usr/local/lib signifie que vous avez essayé d'installer numpy 'manuellement', ce qui peut s'avérer un processus fastidieux.

Le moyen le plus simple consiste à supprimer /usr/local/lib/python2.7/site-packages/numpy et à vous assurer que le package python-numpy est installé (Sudo apt-get install python-numpy).

3
Thomas K

J'y ai passé deux jours avant d'essayer d'importer cv2 dans l'interprète. J'ai vu là-bas qu'il y avait un problème avec numpy. Je suis allé à la chasse et j'ai supprimé numpy du dossier itinérant:

C:\Utilisateurs [nom]\AppData\Roaming\Python\Python35\site-packages

PyCharm redémarré, il s'est reconfiguré et tout allait bien. Aucune réinstallation de numpy n’a été nécessaire, car auparavant, dans mon cas, il devait y avoir un doublon avec une non-concordance de version.

1
kalqlate

Ce qui suit l'a corrigé pour moi

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

Je devais faire le "Sudo pip uninstall numpy" plusieurs fois

0
Martin Thoma