Activate environment with Anaconda3 installed from the Win10 AppStore

I am not new at programming. But I am new at using Python + Anaconda3. I am using Windows 10. I could not find a solution to my issue on any website and the keyword “appstore” doesn’t appear on this forum, therefore this new topic.

I am running my custom made windowed scripts directly by double-clicking on the MyScript.py files on my file explorer. To achieve this, the .py file extension has been associated to pythonw.exe in the Anacoda3 installation folder. This was running good until I added a new dependency to a project which led me to a script running perfectly in the IDE (Spyder or PyCharm) but instantly crashing when double-clicked. I had to run the script with python.exe to understand the dependency issue “ImportError: Unable to import required dependencies”.

After some reading I understood that associating .py files to pythonw.exe is not always enough: My Anaconda3 environment need to be activated on my OS. I could not find a simple way to to this (other than editing PATH variable myself according to a process/path that kept changing in the past). I am looking for a more basic and automated way for doing this.

The process must be kept simple since I am sharing these scripts to workmates with no IT skills. Asking them to edit their PATH seems too dangerous. Moreover, due to restrictions in my organization, Anaconda3 is installed on our computers using the Windows 10 AppStore instead of the Installation Package. Thus, we do not have the chance to select the “Add to PATH” option during the (silent) installation. I do want to keep using the AppStore for this installation.

Some ideas:

  1. Is there a solution to check the “add to PATH” option after the end of the silent installation process ?

  2. Is there a solution to force the windows AppStore to show the “Add to PATH” option instead of doing its silent installation ?

  3. Shall I wrap all my XXX.py scripts with XXX.bat files that will first setup PATH and then launch my XXX.py scripts in an “activated environment” ? This is not sexy at all. Plus I have no idea how to retrieve the Anaconda3 installation path. I would have to hard-code the path.

  4. Isn’t there any GUI among the default ANACONDA tools that can directly fiddle with the PATH settings to activate the default ANACONDA3 environment ?

  5. Is there a command to run one-time in the powershell of Anaconda3 that can setup the windows PATH properly?

Thank you for your help.

So after some discussions with a workmate I understood that changing the PATH is not recommended anyways. So I resolved using a batch file as a launcher.

[ActivateEnv.bat]
@echo off
set PATH=%PATH%;C:\ProgramData\Anaconda3;C:\ProgramData\Anaconda3\condabin
cmd /k conda activate

This will activate (base) environment and prompt the user for a shell command.
Then I can drag-and-drop a python script (or even a shortcut to it from my desktop) on the shell and press ENTER which will launch my GUI-based script.
Then I will exit the shell and my python GUI will keep running.

Note:
This behavior is still based on *.py file association with pythonw.exe.
This is less sexy than double-clicks but simple enough and “grey-box” enough to catch unexpected behaviors from the conda environment.

1 Like