Select to view content in your preferred language

Trying to configure ArcGIS Pro/ArcPy + VS Code, but can't activate conda environment - where am I going wrong?

25128
30
Jump to solution
10-11-2022 06:59 AM
mfcallahan
Frequent Contributor

I'm attempting to configure VS Code for ArcPy/ArcGIS Pro development, and things have been going ok so far, however I have run into an issue I am not sure how to resolve. I'm also curious to hear how other in the community have configured VS Code - I want to make sure I'm not way off base. Here is how I have configured VS Code:

I first cloned a Python environment from the ArcGIS Pro Package Manager, and then set the location of the Python interpreter in VS Code to the "python.exe" in my cloned env (which for me, was in this folder: %LocalAppData%\ESRI\conda\envs\my-cloned-environment\python.exe).

select_interpreter

 And that was actually all I needed to do in order to run and debug a script. I am able to create a new Python debugging configuration in VS Code, set breakpoints step through the code, and get IntelliSense on all ArcPy modules & methods. However, there is still something I am not fully understanding, I think..

On VS Code Terminal launch, I get the following error:

not_activated

 That looks to me like the system PATH environment variable has not been configured for Conda, and Powershell does not recognize the conda command. The Conda docs actually recommend not modifying the PATH env var, but if I do, I can resolve the error above, and the conda command is recognized.

However, that yields another error, "CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.”

working1-1

 Looking at the error message, I see that it is saying to run command conda init powershell, however, this also yields an error an I am stuck at this point, unsure how to proceed. Running VS Code as admin did not resolve the issue.

conda_2

 To further compound my confusion, I came across this in the Esri docs saying "propy.bat" or "proenv.bat" should be used, but I don't know how I would integrate with VS Code:

https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/using-conda-with-arcgis-pro.htm

I'm curious to hear how other VS Code users have their local development environment configured, if you ran into any of these issues, how you resolved them, etc. Or am I just completely way off base in my methods and attempts to get VS Code configured lol??

30 Replies
PhilipOrlando
Occasional Contributor

I'm encountering similar issues that the solution listed here does not solve. VS Code settings like "Conda path" do not exist in the latest version, and other breaking changes related to spaces in file paths appear to block the ArcGIS Pro conda environment from being configured from within VS Code. 

I've opened this issue on the VS Code Python Environment extension GitHub repo that includes more details. 

So far, the only workaround that I've found is to launch VS Code from the "Python Command Prompt" after activating my cloned conda environment. From here, VS Code works as expected with conda, and I'm able to develop and test within the IDE without any issues. 

I hope this helps another unfortunate soul who's been cursed with having to use ArcGIS for work.