简体   繁体   English

“导入错误:无法导入名称多数组”

[英]"ImportError: Cannot import name multiarray"

New programmer here.新程序员来了。

I'm trying to run a script in the Windows command prompt but I'm having issues importing the numpy package and I don't know what's going wrong/how to fix it.我正在尝试在 Windows 命令提示符下运行脚本,但在导入 numpy 包时遇到问题,我不知道出了什么问题/如何修复它。 When I run the script in iPython, it works perfectly.当我在 iPython 中运行脚本时,它运行良好。 However, when I'm running it in the command prompt, I get the following:但是,当我在命令提示符下运行它时,我得到以下信息:

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

I uninstalled numpy using我卸载了 numpy 使用

pip uninstall numpy

Although it worked, it gave me this:虽然它有效,但它给了我这个:

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'

I checked after with pip show numpy that it was deleted - it was - and then reinstalled using: pip install numpy , however I am still having the same import problem.我用 pip show numpy 检查它已被删除 - 它是 - 然后使用: pip install numpy重新pip install numpy ,但是我仍然遇到相同的导入问题。 Does anyone know what's going on?有谁知道发生了什么?

I had the same problem with python3.7 on Ubuntu 18.04 and the solution was:我在 Ubuntu 18.04 上使用 python3.7 遇到了同样的问题,解决方案是:

 sudo -H python3.7 -m pip uninstall numpy sudo apt purge python3-numpy sudo -H python3.7 -m pip install --upgrade pip sudo -H python3.7 -m pip install numpy

Looks like the numpy installation is corrupted in some kind of way.看起来 numpy 安装以某种方式损坏。 I can see in the logs that you are using Anaconda, but when you use pip install on an environment that anaconda installed it can make a bit of a mess.我可以在日志中看到您正在使用 Anaconda,但是当您在pip install了 anaconda 的环境中使用pip install时,它可能会造成一些混乱。

Try this:尝试这个:

pip uninstall numpy
conda install -c anaconda numpy

I had the same issue with Python 3.7, I was in fact installing the wrong version of Numpy (for Python 3.6).我在 Python 3.7 上遇到了同样的问题,实际上我安装了错误版本的 Numpy (对于 Python 3.6)。 The solution was to reinstall for the correct version using the following command:解决方案是使用以下命令重新安装正确的版本:

python3.7 -m pip install numpy python3.7 -m pip install numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM