【问题标题】:Using Python Script in Power BI, ImportError: Missing required dependencies ['numpy']在 Power BI 中使用 Python 脚本,ImportError: Missing required dependencies ['numpy']
【发布时间】:2021-11-05 04:06:56
【问题描述】:

我是Power BI 的新手,我尝试在其中设置 python 脚本。 我更改了选项并激活了Python scripting。之后我得到错误:

DataSource.Error: ADO.NET: Python script error.
Traceback (most recent call last):
  File "PythonScriptWrapper.PY", line 2, in <module>
    import os, pandas, matplotlib.pyplot
  File "C:\Users\mm\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']

Details:
    DataSourceKind=Python

我检查了conda 列表,它包含numpy

我又安装了numpypandas,收到了下面的信息

C:\Users\mm\AppData\Local\Continuum\anaconda3>py -m pip install numpy
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: numpy in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (1.15.4)

C:\Users\mm\AppData\Local\Continuum\anaconda3>py -m pip install pandas
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: pandas in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (0.23.4)
Requirement already satisfied: python-dateutil>=2.5.0 in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (from pandas) (2.7.5)
Requirement already satisfied: pytz>=2011k in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (from pandas) (2018.7)
Requirement already satisfied: numpy>=1.9.0 in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (from pandas) (1.15.4)
Requirement already satisfied: six>=1.5 in c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)

如您所见,我使用的是 anaconda3,但我的机器上安装了另一个 Python。我尝试了很多方法,但没有任何帮助

【问题讨论】:

  • 您可以尝试从 anaconda 提示符而不是 cmd 运行 pip install 命令吗?
  • 我也在 anaconda 提示符下做了,它说:“要求已经满足:c:\users\mm\appdata\local\continuum\anaconda3\lib\site-packages 中的 numpy (1.15.4) " 但我在 powerbi 上仍然遇到同样的错误。 (我也做了“刷新预览”)

标签: python numpy powerbi


【解决方案1】:

打开 Anaconda 提示: 然后,您必须转到要在 PowerBI 中使用的 Conda 环境。我有一个环境“临时”,所以我首先在“Anaconda Prompt”中激活它:

(base) C:\Users\ashish>conda activate temp

然后我转到安装文件夹中有“PowerBI”可执行文件的目录:

(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"

然后,我从提示启动 PowerBI:

(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe

这修复了您遇到的 NumPy 错误。如果您希望任何其他软件包与 PowerBI 一起使用,请将该软件包安装在相应的“Conda 环境”中(在我的情况下是“temp”)。

【讨论】:

    【解决方案2】:

    忘记 Anaconda 并使用 WinPython。 我用 StackOverflow 和其他论坛中提供的所有解决方法尝试了 Anaconda 好几天,但他们无处可去。 然后我尝试了 WinPython,它立即生效。当然,您需要相应地更改 PowerBI 选项。

    1. 安装 WinPython:https://github.com/winpython/winpython
    2. 更改检测到的 Python 主目录:https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts#enable-python-scripting

    如果您认为我的回答高于其他人,则无需降级 Python、PBI 或其他任何东西。

    【讨论】:

      【解决方案3】:

      我在尝试让 Power BI 使用 Anaconda Python 时遇到了类似的问题。看到post about PBI having issues with Python 3.7后我:

      1. 使用 Anaconda Navigator 在 Anaconda 中创建了一个新环境,并确保新环境使用的是 Python 3.6(所以不是 3.7)。
      2. 在那个环境中安装了我的 Power BI Python 脚本中使用的 Pandas、Matplotlib 和 Seaborn 等包
      3. 转到 Power BI 的设置:文件/选项和设置/选项/Python 脚本并为检测到的 Python 主目录设置“其他”,而是导航到我的新 3.6 python 环境目录(在屏幕底部的 Anaconda Navigator 中可见选择该环境时)

      ..效果很好。

      【讨论】:

        【解决方案4】:

        我认为这个错误可能是由于 Anaconda 发行版的一些 numpy 问题。 我将 Power BI 中的 Python 路径更改为虚拟环境(使用 pip 而不是 conda 来安装 numpy 和其他包),我没有更多问题。

        【讨论】:

          猜你喜欢
          • 2019-09-16
          • 1970-01-01
          • 2020-01-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-01
          • 2021-12-03
          • 2021-12-14
          相关资源
          最近更新 更多