Python 导入错误:缺少必需的依赖项 ['numpy']
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42973666/
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
ImportError: Missing required dependencies ['numpy']
提问by aAAAAAAa
I was able to run all scripts successfully which is using pandas , but suddenly all my PANDAS SCRIPTS are giving this error :
我能够成功运行所有使用 pandas 的脚本,但突然间我所有的 PANDAS SCRIPTS 都出现此错误:
Traceback (most recent call last):
回溯(最近一次调用最后一次):
File "data_visulaization.py", line 5, in
文件“data_visulaization.py”,第 5 行,在
import pandas as pd
File "/usr/lib64/python2.7/site-packages/pandas/init.py", line 18, in
文件“/usr/lib64/python2.7/site-packages/pandas/初始化py”为18行,在
raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Recently i have not installed or updated any new things.
最近我没有安装或更新任何新东西。
Does anyone have a solution for this?
有没有人对此有解决方案?
I uninstalled pandas and numpy and re-installed them but still facing the same issue.
我卸载了 pandas 和 numpy 并重新安装了它们,但仍然面临同样的问题。
采纳答案by aAAAAAAa
I found the solution , the actual problem is if any of your recent python scripts have generated ".pyc" extension file this error will occur .
我找到了解决方案,实际问题是如果您最近的任何 python 脚本生成了“.pyc”扩展文件,就会发生此错误。
solution is to delete those files that's all.
解决方案是删除那些文件。
回答by Shtefan
I got this issue on Rasberry PI and found that the root cause was missing library:
我在 Rasberry PI 上遇到了这个问题,发现根本原因是缺少库:
import numpy
...
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
Then it takes few minute to google the required library source:
然后花几分钟在谷歌上搜索所需的库源:
sudo apt-get install libatlas-base-dev
I have not checked the solution on any other Linux-es but likely the same method should be applicable. So try to import the faulty library first and see what is missing.
我没有在任何其他 Linux-es 上检查解决方案,但可能同样的方法应该适用。所以尝试先导入有问题的库,看看缺少什么。
回答by ChinuKapoor
I faced the exact same error and found that I had created a file named 'random.pyc' by mistake in the same directory as that of my PyCharm environment ayush@ayush-VirtualBox:~/PycharmProjects/untitled$where "untitled" refers to my project directory. I deleted it and everything fells into place. Hope this helps !
我遇到了完全相同的错误,发现我错误地在与 PyCharm 环境相同的目录中创建了一个名为“random.pyc”的文件 ayush@ayush-VirtualBox:~/PycharmProjects/untitled$其中“untitled”是指我的项目目录。我删除了它,一切都到位了。希望这可以帮助 !
The reason for this was numpy Imports another file called Random by default for building its own dependencies and it mistook my 'random.pyc' for it and replaced it.
这样做的原因是 numpy 默认情况下导入另一个名为 Random 的文件来构建自己的依赖项,它误将我的 'random.pyc' 误认为它并替换了它。
回答by Moniba
I had the same error. Fixed with the following:
我有同样的错误。修复了以下内容:
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
回答by Aaron
use"conda install numpy" in cmd-window if you used Anaconda in your machine. I had encount this problem also and I resolved it by this. May it can help U.
如果您在机器中使用 Anaconda,请在 cmd-window 中使用“conda install numpy”。我也遇到过这个问题,我通过这个解决了它。愿它可以帮助U。
回答by clarked
This error will occur when multiple versions of numpy are installed. Check to make sure you only have one version of numpy installed. You can make a test file to check this if you don't want to look through the directories:
安装多个版本的numpy时会出现这个错误。检查以确保您只安装了一个版本的 numpy。如果您不想查看目录,可以制作一个测试文件来检查这一点:
import numpy
print("Numpy imported")
If you get an error saying that multiple versions of numpy were detected, then you have multiple versions of numpy installed.
如果您收到一条错误消息,指出检测到多个版本的 numpy,那么您安装了多个版本的 numpy。
You can fix this by repeatedly calling (not just once)
pip uninstall numpy
until all versions are uninstalled and then use
pip install numpy
to get only the latest version.
您可以通过重复调用(不仅仅是一次)来解决此问题,
pip uninstall numpy
直到卸载所有版本,然后使用它
pip install numpy
来仅获取最新版本。
回答by Fatih1923
If you are using packages
options and it contains pandas or some package depends numpy
, you should add required dependencies to the packages
.
如果您正在使用packages
options 并且它包含 pandas 或某些依赖包numpy
,则应将所需的依赖项添加到packages
.
回答by blacksheep
pip uninstall numpy
pip install numpy
It works
有用
回答by Hyman Rusty
try uninstalling pandas and numpy:
尝试卸载 pandas 和 numpy:
pip uninstall pandas
pip uninstall numpy
pip uninstall pandas
pip uninstall numpy
and install them back:
并将它们安装回去:
pip install pandas
pip install numpy
pip install pandas
pip install numpy