【问题标题】:Pandas Missing required dependencies ['numpy']熊猫缺少必需的依赖项['numpy']
【发布时间】:2019-06-06 17:18:40
【问题描述】:

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

ImportError: 缺少必需的依赖项 ['numpy']。

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

【问题讨论】:

  • 先安装numpy。
  • 我做到了,并收到:要求已经满足:/usr/local/lib/python2.7/site-packages 中的 numpy。那为什么我再试一次,我得到了同样的错误。
  • 我认为numpy版本与pandas不兼容。
  • 你能import numpy吗?如果是这样,那么你的熊猫就坏了
  • 当我尝试时,我得到了这个:

标签: python pandas numpy


【解决方案1】:

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

如果您想了解有关在 Mac 上安装 Python 环境以进行机器学习的更多信息,请访问 machinelearningmastery.com 上的 tutorial

【讨论】:

    【解决方案2】:

    这与不兼容没有任何关系。正如@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
    

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

    【讨论】:

    • 是的,我没有使用 anaconda,但现在它可以工作了。谢谢!
    【解决方案3】:

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

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

    这对我有用!

    【讨论】:

      【解决方案4】:

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

      测试代码:import_pandas.py:

      import pandas
      print('Pandas import succeeded!')
      

      使用 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']
      

      但是,激活 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!
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-27
        • 1970-01-01
        • 2017-07-01
        • 2017-06-11
        相关资源
        最近更新 更多