Forum Discussion

jono's avatar
jono
Frequent Visitor
7 years ago
Solved

importing dataframe with python throws script error

When I try to import a dataframe to Power BI using a Python script I get the following error

 

Details: "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\jonow\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
"

 

This happens even when I enter no Python code, and the code runs fine in an IDE.

I am using Python with anaconda so the file Path I have specified in Power BI is C:\Users\Username\Anaconda3

Is this correct ? ? ? 

Tried everything and cant get this working.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello,

    I have the same problem.  I kind of understand why.  I am also using Anaconda and I get the same error when I try to run a query:

     

    File "PythonScriptWrapper.PY", line 2, in <module>
        import os, pandas, matplotlib.pyplot
      File "C:\Users\bharat.c.ruparel\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
        DataSourcePath=Python
        Message=Python script error.
    Traceback (most recent call last):
      File "PythonScriptWrapper.PY", line 2, in <module>
        import os, pandas, matplotlib.pyplot
      File "C:\Users\bharat.c.ruparel\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']
        ErrorCode=-2147467259
        ExceptionType=Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScr
     
    The reason that this is happening is numpy is a dependency for pandas package and your environment must be able to find this package when it calls "import pandas".  Anaconda manages this process by "activating" the conda environment BEFORE importing anything by running the activate.bat file.  In my case it is located at:
     
    C:\Users\bharat.c.ruparel\AppData\Local\Continuum\anaconda3\Scripts\activate.bat
     
    This needs to be run to set up the conda environment.  I do not know how to run this batch file from within Power BI so that it can find the necessary dependencies.
     
    does anyone know?
      • Anonymous's avatar
        Anonymous
        Not applicable

        So I could not solve it using the service approach.  Besides, it is kind of hackish.  I ended up doing another straight Python install using the conventional windows installer and then pip installing the pandas package.  I put this intalled version of Python in the PATH environment variable.

         

        So I have two installations of the same versions of Python 3.7.  One with Anaconda, and another by itself.  Since the standalone Python does not require activation of the Conda environment, it worked fine.

         

        I know it is sub-optimal, but it works.  Power BI developers need to support different Pyenv and Conda environments in the future releases of Python support.

         

        Bharat

  • v-yuta-msft's avatar
    v-yuta-msft
    Community Support

    Hi jono,

     

    This may caused by numpy module hasn't be installed when you installed anaconda. You can open CMD and type "conda list" to check all the modules included by anaconda, if numpy is not listed, type "conda install numpy" to install numpy module.

     

    Regards,

    Jimmy Tao