Hello,
I have a situation where I have a cloned environment (arcgispro-py3-clone) and 'conda activate' is not successful within VS code. I would like to run my python toolbox and VS code being able to ID that i am in my (arcgispro-py3-clone) environment.
Traceback (most recent call last):
File "C:\Users\username\Anaconda3\Scripts\conda-script.py", line 11, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
I ran the following command in proenv.bat :
conda activate arcgispro-py3-clone
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
And then ran conda init powershell:
conda init powershell
WARNING: Cannot install xonsh wrapper without a python interpreter in prefix: C:\Program Files\ArcGIS\Pro\bin\Python
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\conda.exe
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\conda-env.exe
no change C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\conda-script.py
no change C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\conda-env-script.py
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\conda.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Library\bin\conda.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\_conda_activate.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\rename_tmp.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\conda_auto_activate.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\conda_hook.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\activate.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\activate.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\condabin\deactivate.bat
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\activate
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\deactivate
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\etc\profile.d\conda.sh
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\etc\fish\conf.d\conda.fish
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\shell\condabin\Conda.psm1
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\shell\condabin\conda-hook.ps1
needs sudo C:\Program Files\ArcGIS\Pro\bin\Python\etc\profile.d\conda.csh
modified C:\Users\username\Documents\WindowsPowerShell\profile.ps1
==> For changes to take effect, close and re-open your current shell. <==
Operation failed.
I was following this discussion Enhance isolated conda installation to support conda init and was able to use the conda-hook.ps1 script that the main anaconda installation provides. This resource was helpful as well Setting up Windows Terminal to launch an ArcGIS Pro Python prompt - Nithiya Streethran
The windows terminal approach worked fine and 'conda activate' works as intended until I realize that the windows terminal is referencing this base environment (running the 'conda info' command):
C:\Users\username\Anaconda3 (writable)
However the C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\proenv.bat (this is the Python command prompt that ArcPro provides) references this base environment:
C:\Program Files\ArcGIS\Pro\bin\Python
My VS code has the python default interpreter set to :
PS C:\Users\username> & "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3-clone/python.exe" c:/Users/username/Documents/ArcGIS/Projects/file.pyt
Note how there is no environment name before the PS -- ie (arcgispro-py3-clone).
The windows terminal option does allow me to activate new environments while the proenv.bat does not. This leads me to consider maybe just using the windows terminal to install packages and switch between environments and be OK with VS code not displaying the environment name ?
Since both the proenv.bat terminal and windows terminal have an 'active env location' set to: 'C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3-clone'.
Does this mean that python.exe found in my clone will understand where to find newly installed packages and I can proceed with developing my python toolbox in VS code?
@Luke_Pinner @omdaniel I know you all discussed this to some degree in a different community board but if you have any insight into the way that proenv.bat is interacting with cloned environments and the need to install packages I'm all ears! Thank you!
Looking a bit closer to this post Trying to configure ArcGIS Pro/ + VS Code @Brian_Wilson suggested to ignore the conda init recommendation and ONLY use the scripts that ArcPro provides. Which means running 'proenv', then running "activate". (at first i thought this meant running 'conda activate'). Its amazing what taking time away from a computer screen and going for a walk will do!
Anyway, it finally makes a bit more sense that "C:\Program Files\ArcGIS\Pro\bin\Python\Scripts" is added to the PATH env variable. Since any executable file in the directories listed in PATH can be executed without specifying the full path to the file. This allows you to run those executable files with only the file name from the command line. For this use case, its executing proenv and activate.