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?

13328
25
Jump to solution
10-11-2022 06:59 AM
mfcallahan
Occasional Contributor II

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??

0 Kudos
25 Replies
Scoth
by
New Contributor III

If the accepted solution didn't help, could it be the version of Conda isn't compatible with VSCode? My version of VSCode (1.78.2) seems to require Conda 4.4+. I have ArcPro 3.1 and it came with Conda 4.14, which isn't working with the accepted solution.

Scoth_1-1694194960136.png

 

 

0 Kudos
Brian_Wilson
Regular Contributor II

I am running VSCode 1.82.0 and it says it wants conda > 4.4 too, and it works fine with 4.14 and also with the current Miniconda3 version. I am on Windows 11. What is it doing wrong for you?

 

 

0 Kudos
Scoth
by
New Contributor III

It can't seem to activate conda. It does run the script otherwise, though *shrug.Scoth_0-1694470434711.png

 

0 Kudos
Brian_Wilson
Regular Contributor II

Last Friday I tried switching again to use ONLY the Esri install of conda and friends but it's just not worth it. I switched back over to use Miniconda in VScode (and at the command line) again.

It whined and made me run "conda init" again but I did and now I am back working from both VSCODE and command line. I think the "conda init" requirement is awful but at least this time it almost worked for me. (It edits my startup files but not the right ones. I still have to copy its changes into my .bashrc file.)

I installed Miniconda to C:/Users/bwilson/Miniconda3, and added CONDA_PATH="C:\Users\bwilson\Miniconda3\Scripts" to my environment, launched a new shell, then did "conda activate arcgis_tools" and indeed it gave me the CommandNotFound error. Then I ran "conda init bash" and then copied the gunk it added to my .bash_profile to the .bashrc that I use

Super easy ha ha ha kidding. Stupidly complex.

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I tired everything in this post a few times and I am stuck also.  This was not an issue in Pro 2.9 but 3.13 I got today and keep getting the message.

Also getting this message \profile.ps1 is not digitally signed in red.  Maybe since I do not have admin rights.

 

For the person that posted to edit setting.json which one and where?  

thanks

0 Kudos
DougBrowning
MVP Esteemed Contributor

I finally got it @Brian_Wilson .  Then got some new ones and fixed those also.

First

In File explorer go here C:\Program Files\ArcGIS\Pro\bin\Python\Scripts

Open powershell in this dir by Right clicking – Powershell – Open here

Then run this command

.\activate.bat

 

Second 

Open settings.json 

      In VSCode Ctrl + Shift + P.  Then search for settings and click the Preferences: Open User Settings (JSON)

     Or close VS and go to C:\Users\[YouUserNameHere]\AppData\Roaming\Code\User and edit the settings.json with notepad

You should see a powershell section section like this - add the line 

"args": ["-ExecutionPolicy", "Bypass", "-NoLogo"
- see below in bold

If not add all of this below

"python.terminal.activateEnvironment": false
"terminal.integrated.profiles.windows": {

    "PowerShell": {
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": ["-ExecutionPolicy", "Bypass", "-NoLogo"]
    },
    "Command Prompt": {
        "path": [
            "${env:windir}\\Sysnative\\cmd.exe",
            "${env:windir}\\System32\\cmd.exe"
        ],
        "args": [

        "/k",
        "C:/Program Files/ArcGIS/Pro\\bin/Python/Scripts/proenv.bat"],
        "icon": "terminal-cmd"
    },
    "Git Bash": {
        "source": "Git Bash"
    }
}
}
 
Third if you use UNC paths (and you should) then it will give security warnings.  You can fix this by adding another line to settings.json and give it your company UNC domains both full qualified and not.  Not sure what the wsl$ does but I have it based on posts.
"security.allowedUNCHosts": ["wsl$","[Your UNC Root","Your UNC root.something.com"],
 
Look for section Like this add line in Bold
{

    "launch": {
        "configurations": [
       
        ]
    },
  "security.allowedUNCHosts": ["wsl$","[Your UNC Root","Your UNC root.something.com"],
    "python.defaultInterpreterPath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\python.exe",
    "[python]": {
        "editor.formatOnType": true
    },
    "python.condaPath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\Scripts",
    "workbench.colorTheme": "Default Light Modern"

"python.terminal.activateEnvironment": false
"terminal.integrated.profiles.windows": {
 
This so far has cleared up all warnings and it starts clean.
Hope that helps someone took forever.
0 Kudos