Python 导入opencv并获取numpy.core.multiarray导入失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28157976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Importing opencv and getting numpy.core.multiarray failed to import
提问by NoTrueScotsman
Trying to install OpenCV and running into an issue where attempting to import cv2 results in this output -
尝试安装 OpenCV 并遇到尝试导入 cv2 导致此输出的问题 -
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import
I'm running on Windows 7 x64, Python v 2.7.9 Thanks!
我在 Windows 7 x64 上运行,Python v 2.7.9 谢谢!
采纳答案by chris
The error is telling you that you have an out of date version of numpy. If you used pip
to install things you can simply run pip install numpy -U, or download the appropriate version from their website.
该错误告诉您 numpy 的版本已过时。如果你曾经pip
安装过东西,你可以简单地运行 pip install numpy -U,或者从他们的网站下载合适的版本。
回答by alexfigtree
In case
如果
pip install -U numpy
pip install -U numpy
doesn't work (even with sudo), you may want to make sure you're using the right version of numpy. I had the same "numpy.core.multiarray failed to import" issue, but it was because I had 1.6 installed for the version of Python I was using, even though I kept installing 1.8 and assumed it was installing in the right directory.
不起作用(即使使用 sudo),您可能需要确保使用正确版本的 numpy。我有同样的“numpy.core.multiarray 无法导入”的问题,但这是因为我为我使用的 Python 版本安装了 1.6,即使我一直安装 1.8 并假设它安装在正确的目录中。
I found the bad numpy version by using the following command in my Mac terminal:
我在 Mac 终端中使用以下命令发现了错误的 numpy 版本:
python -c "import numpy;print numpy.version;print numpy.file";
蟒蛇-c“进口numpy的;打印numpy的版本;打印numpy的文件”;
This command gave me the version and location of numpy that I was using (turned out it was 1.6.2). I went to this location and manually replaced it with the numpy folder for 1.8, which resolved my "numpy.core.multiarray failed to import" issue. Hopefully someone finds this useful!
这个命令给了我我正在使用的 numpy 的版本和位置(结果是 1.6.2)。我去了这个位置并手动将其替换为 1.8 的 numpy 文件夹,这解决了我的“numpy.core.multiarray 无法导入”问题。希望有人觉得这很有用!
回答by phil294
linux: sudo apt-get install python-numpy
linux: sudo apt-get install python-numpy
回答by Ahmed J.
if you are using ubuntu bionic beaverthen try running: sudo apt-get install python-numpy
had the same issue, resolve by running the above command.
Hope it helps
如果您使用的是ubuntu 仿生海狸,请尝试运行:sudo apt-get install python-numpy
遇到同样的问题,请通过运行上述命令解决。希望能帮助到你