0 votes
1 view
in BI by (17.6k points)

I am trying to work with Python in my Windows 10 Machine. My Anaconda environment can be set by executing the following command:

c:\Users\bharat.c.rupare.> call c:\Users\bharat.c.ruparel\AppData\Local\Continuum\anaconda3\Scripts\activate.bat

this sets up the anaconda environment and then I am good to go. However, I am trying to run Python code using numpy and pandas which are pre-installed in the Anaconda stack within Power BI. When I do that, Power BI complains that it cannot find numpy. I understand why; because the anaconda environment has not been activated from within Power BI.

What do I need to do to activate the anaconda environment so that Power BI can find the python packages such as numpy, pandas? 

1 Answer

0 votes
by (47.2k points)
selected by
 
Best answer
  • You must use the menu in Power BI Desktop to navigate to File / Options and settings / Options / GLOBAL / Python scripting and then set the required Python home directory.

  • You haven't provided enough info to understand which directory to choose, as your activate.bat script could contain anything. But a likely guess would be the path to your activate.bat, removing the Scripts sub-folder. The folder you choose should contain the file: python.exe.

  • You have to import these modules in the code.if you have an old version of pip you can simply do this:

import pip

pip.main(['install', 'numpy'])

pip.main(['install', 'pandas'])

import numpy as np

....

  • if you have a newer version(after 10.0) of pip(import pip and run pip.__version__), you will need to use subprocess;

import subprocess

subprocess.check_call(["python", '-m', 'pip', 'install', 'numpy'])

subprocess.check_call(["python", '-m', 'pip', 'install', 'pandas'])

import numpy as np

....

Related questions

0 votes
2 answers
asked Oct 3, 2019 in Python by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 3 in BI by dev_sk2311 (14.3k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...