Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lucazav/c742b8789dbe04848523f0496cbff75e to your computer and use it in GitHub Desktop.

Select an option

Save lucazav/c742b8789dbe04848523f0496cbff75e to your computer and use it in GitHub Desktop.
Run Power BI in a conda environment from a batch file
@echo OFF
rem How to run Power BI Desktop in a given conda environment from a batch file.
rem It doesn't require:
rem - conda to be in the PATH
rem - cmd.exe to be initialized with conda init
rem Define here the path to your conda installation
rem If you installed [Anaconda/Miniconda] just for your user, you'll find the installation folder in C:\Users\your-username\[AnacondaX/MinicondaX]
rem If you installed [Anaconda/Miniconda] for all the users, you'll find the installation folder in C:\ProgramData\[AnacondaX/MinicondaX]
set CONDAPATH=C:\Users\your-username\miniconda3
rem Define here the name of the environment. Use "base" for the base environment
set ENVNAME=your-environment-name
rem The following command activates the base environment.
rem call C:\ProgramData\Miniconda3\Scripts\activate.bat C:\ProgramData\Miniconda3
if %ENVNAME%==base (set ENVPATH=%CONDAPATH%) else (set ENVPATH=%CONDAPATH%\envs\%ENVNAME%)
rem Activate the conda environment
rem Using call is required here, see: https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files
call %CONDAPATH%\Scripts\activate.bat %ENVPATH%
rem Run a python script in that environment
"C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
rem Deactivate the environment
call conda deactivate
rem If conda is directly available from the command line then the following code works.
rem call activate your-environment-name
rem "C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
rem conda deactivate
rem One could also use the conda run command
rem conda run -n your-environment-name "C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment