Nouveau programmeur ici.
J'essaie d'exécuter un script dans l'invite de commande Windows, mais j'ai des problèmes pour importer le package numpy et je ne sais pas ce qui ne va pas/comment y remédier. Lorsque j'exécute le script dans iPython, cela fonctionne parfaitement. Cependant, lorsque je l'exécute dans l'invite de commandes, j'obtiens ce qui suit:
Traceback (most recent call last):
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 16, in <module>
from . import multiarray
ImportError: cannot import name multiarray
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\James\Documents\Chemistry Year Three\Python
programming\untitled1.py", line 12, in <module>
import numpy
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\__init__.py", line
142, in <module>
from . import add_newdocs
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\add_newdocs.py",
line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\lib\__init__.py",
line 8, in <module>
from .type_check import *
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\lib\type_check.py",
line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\James\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
J'ai désinstallé numpy en utilisant
pip uninstall numpy
Bien que cela ait fonctionné, cela m'a donné ceci:
Proceed (y/n)? y
Successfully uninstalled numpy-1.13.3
Exception:
Traceback (most recent call last):
File "c:\users\james\anaconda3\lib\shutil.py", line 387, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied:
'C:\\Users\\James\\AppData\\Local\\Temp\\pip-uninstall-
_v4vz8dq\\users\\james\\anaconda3\\lib\\site-
packages\\numpy\\core\\multiarray.cp36-win_AMD64.pyd'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\james\anaconda3\lib\site-
packages\pip\_internal\cli\base_command.py", line 143, in main
status = self.run(options, args)
File "c:\users\james\anaconda3\lib\site-packages\pip\_internal\commands\uninstall.py", line 78, in run
uninstall_pathset.commit()
File "c:\users\james\anaconda3\lib\site-packages\pip\_internal\req\req_uninstall.py", line 275, in commit
self.save_dir.cleanup()
File "c:\users\james\anaconda3\lib\site-packages\pip\_internal\utils\temp_dir.py", line 81, in cleanup
rmtree(self.path)
File "c:\users\james\anaconda3\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "c:\users\james\anaconda3\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
raise attempt.get()
File "c:\users\james\anaconda3\lib\site-packages\pip\_vendor\retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "c:\users\james\anaconda3\lib\site-packages\pip\_vendor\six.py", line 693, in reraise
raise value
File "c:\users\james\anaconda3\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "c:\users\james\anaconda3\lib\site-packages\pip\_internal\utils\misc.py", line 111, in rmtree
onerror=rmtree_errorhandler)
File "c:\users\james\anaconda3\lib\shutil.py", line 494, in rmtree
return _rmtree_unsafe(path, onerror)
File "c:\users\james\anaconda3\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\users\james\anaconda3\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\users\james\anaconda3\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
[Previous line repeated 3 more times]
File "c:\users\james\anaconda3\lib\shutil.py", line 389, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "c:\users\james\anaconda3\lib\site-packages\pip\_internal\utils\misc.py", line 123, in rmtree_errorhandler
func(path)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\James\\AppData\\Local\\Temp\\pip-uninstall-_v4vz8dq\\users\\james\\anaconda3\\lib\\site-packages\\numpy\\core\\multiarray.cp36-win_AMD64.pyd'
J'ai vérifié après avec pip show numpy qu'il a été supprimé - il l'était - puis réinstallé en utilisant: pip install numpy
, mais j'ai toujours le même problème d'importation. Quelqu'un sait-il ce qui se passe?
Il semble que l'installation de numpy soit corrompue d'une manière ou d'une autre. Je peux voir dans les journaux que vous utilisez Anaconda, mais lorsque vous utilisez pip install
sur un environnement qu'anaconda a installé peut faire un peu de gâchis.
Essaye ça:
pip uninstall numpy
conda install -c anaconda numpy