pandas 熊猫缺少必需的依赖项 ['numpy']

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44220798/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:42:12  来源:igfitidea点击:

Pandas Missing required dependencies ['numpy']

pythonpandasnumpy

提问by sdksmkfnajnf

enter image description here

在此处输入图片说明

I am currently following a beginners introduction to machine learning. While entering in the command: import pandas as pdin the python shell in terminal, I get an error reading:

我目前正在关注机器学习的初学者介绍。在输入命令时: import pandas as pd在终端的 python shell 中,我收到一条错误消息:

ImportError: Missing required dependencies ['numpy'].

导入错误:缺少必需的依赖项 ['numpy']。

I already looked at the other similar question, tried that solution, but still received the same error.

我已经看过另一个类似的问题,尝试过该解决方案,但仍然收到相同的错误。

采纳答案by Peter van Heusden

Looks like you might be running on a Mac and perhaps using the default system python. For whatever reason you don't have a complete installation. you have pandasbut not numpy. I'm not sure which packages the tutorial you are following uses, but I would recommend installing the Anaconda python distributionas it includes pandas, all its dependencies and much more, including the scikit-learnpackage often used for machine learning.

看起来您可能在 Mac 上运行,并且可能使用默认系统 python。无论出于何种原因,您都没有完整的安装。你有pandas但没有numpy。我不确定您所关注的教程使用了哪些软件包,但我建议安装Anaconda python 发行版,因为它包括pandas、所有依赖项等等,包括scikit-learn经常用于机器学习的软件包。

If you want to know more about installing a Python environment for machine learning on a Mac, there is a good tutorialon machinelearningmastery.com.

如果你想了解更多关于在 Mac 上安装机器学习 Python 环境的信息,machinelearningmastery.com 上有一个很好的教程

回答by Brad Solomon

This doesn't have anything to do with incompatibility. As @Peter mentioned, you simply don't have NumPy and should install through Anaconda. Here is the code within pandas that is giving you the error:

这与不兼容没有任何关系。正如@Peter 提到的,您根本没有 NumPy,应该通过 Anaconda 安装。这是Pandas中给您错误的代码:

# Let users know if they're missing any of our hard dependencies
hard_dependencies = ("numpy", "pytz", "dateutil")
missing_dependencies = []

for dependency in hard_dependencies:
    try:
        __import__(dependency)
    except ImportError as e:
        missing_dependencies.append(dependency)

if missing_dependencies:
    raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
del hard_dependencies, dependency, missing_dependencies

Notice there is nothing here about version.

请注意,这里没有关于版本的任何内容。

回答by mrGreenBrown

I had a same problem. I don't know what is the cause of the problem, but it seems to deal with how numpy is installed. You can try the following:

我有同样的问题。我不知道问题的原因是什么,但它似乎与 numpy 的安装方式有关。您可以尝试以下操作:

  1. Install pandas
  2. Uninstall numpy
  3. Download numpy whl for your needs from here
  4. Install numpy from downloaded whl
  1. 安装Pandas
  2. 卸载 numpy
  3. 这里下载满足您需求的 numpy whl
  4. 从下载的 whl 安装 numpy

That worked for me!

那对我有用!

回答by Peter

I get the same error message with my Anaconda installation when I forget to activate the environment:

当我忘记激活环境时,我的 Anaconda 安装收到相同的错误消息:

Testcode: import_pandas.py:

测试代码:import_pandas.py:

import pandas
print('Pandas import succeeded!')

Run import_pandas.py with ImportError:

使用 ImportError 运行 import_pandas.py:

Microsoft Windows [Version 10.0.16299.1146]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\peter\demo>python import_pandas.py
Traceback (most recent call last):
  File "import_pandas.py", line 1, in <module>
    import pandas
  File "C:\Users\peter\AppData\Local\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

However, after activating conda everything works perfectly fine:

但是,激活 conda 后一切正常:

C:\Users\peter\demo>activate
C:\Users\peter\demo>conda.bat activate

(base) C:\Users\peter\demo>python import_pandas.py
Pandas import succeeded!