Can’t get python scripts to work in Power BI

I currently have anaconda installed on my machine. I have a python script written which is working perfectly in Jupyter Notebook, the next step is I want to execute this script in Power BI to import data and pre-process the data.

I have adjusted the settings in powerBI (correctly I think):

  • Python Directory is set to C:ProgramDataAnaconda3
  • Detected Python IDEs is set to Default OS program for .PY files

Can you provide a solution for the below error. I have spent hours trying to find something.

Error

Details: "ADO.NET: Python script error.
<pi>C:PROGRAMDATAANACONDA3libsite-packagesnumpy__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "PythonScriptWrapper.PY", line 2, in <module>
    import os, pandas, matplotlib
  File "C:PROGRAMDATAANACONDA3libsite-packagespandas__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "C:PROGRAMDATAANACONDA3python.exe"
  * The NumPy version is: "1.18.5"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.

</pi>"

Answer

If you need to run Python scripts in Power BI and have the Anaconda stack installed, it has to be activated before you can use it. Simply open the Anaconda Prompt or run conda activate on the cmd prompt. Then start PBIDesktop from within the activated environment like:

(base) C:> "Program FilesMicrosoft Power BI DesktopbinPBIDesktop.exe"

Make sure the Python home directory (Anaconda3) has been added to the PBIDesktop global options in the Python scripting section too.