Pandas缺少必需的依赖项['numpy']

2024-04-27 02:22:18 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

我现在正在学习机器学习入门。 输入命令时: import pandas as pd在终端中的python shell中,读取以下内容时出错:

ImportError: Missing required dependencies ['numpy'].

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


Tags: import命令numpy机器终端pandasas错误
3条回答

这与不兼容无关。正如@Peter提到的,你根本没有NumPy,应该通过水蟒来安装。以下是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

注意这里没有关于版本的内容。

我也有同样的问题。我不知道问题的原因是什么,但它似乎涉及如何安装numpy。您可以尝试以下操作:

  1. 安装熊猫
  2. 卸载numpy
  3. here下载您需要的numpy whl
  4. 从下载的whl安装numpy

对我有用!

看起来您可能在Mac上运行,并且可能使用默认的系统python。不管是什么原因,你没有一个完整的安装。你有pandas,但没有numpy。我不确定您下面的教程使用的是哪个包,但我建议您安装Anaconda python distribution,因为它包括pandas,它的所有依赖项等等,包括通常用于机器学习的scikit-learn包。

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

相关问题 更多 >