[GIS] ArcGIS Pro Python Interpreter Setup with Visual Studio Code

arcgis-proarcpypythonvisual-studio-code

I'm fairly new to Stack Exchange and not very well-versed in IDE's. I'm struggling to set up the ArcGIS Pro Python interpreter with Visual Studio Code. I have ArcGIS Pro 2.4.3 and VSC 1.44.2. I'm trying to follow the advice on the below thread, but I cannot ask questions in that thread, only add answers.

Original Thread

So here's my question. I cannot find the ""+ Custom…" and select "Configure" location where I add the Python interpreter, as mentioned in the thread above. In VSC I can go ctrl+Shift+P and it shows me the current Python interpreters that the program already knows, but I cannot add a new location. In File–>Preferences–>Settings under Workspace I can search for Python and there are 147 settings for Python.

Python Settings

I tried adding the C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe path under Python Path and adding C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3 under Pipenv Path but this hasn't changed anything in terms of the program understanding that I'm trying to add a new Python interpreter option.

There are so many settings for Python I don't even know where to start or if I am even changing the right settings. It's not very intuitive. Please help!

Best Answer

There are a few different ways you can get VS Code to work with ArcGIS Pro Python. I'm not going to list them all, just the way I've started using for every thing I do.

  1. Make sure you have the Python extension for VS Code installed from the Marketplace
  2. Press CTRL + , (comma) to open the settings. From here if you type pythonpath it'll filter down to some Python specific places under your User settings. Update the following (if the path I used below doesn't match, update as needed)

Python > Auto Complete > Typeshed Paths : C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe

Python > Jedi Path : C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe NOTE -- If Intellisense (code-complete) doesn't seem to work, remove this setting, re-start VS Code and try again.

Python > Python Path : C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe

  1. Finally, I do all my development in a specific folder, generally new to whatever I'm working on. Inside that folder I have the VS Code recognized folder of .vscode. Inside that folder are two files (depending how you setup, they'd be auto-created, but I just copy/paste these files from previous projects to quick-start). See the contents below for settings.json and launch.json.

  2. When you start VS Code, make sure you Open Folder or Open Workspace, not just the file .py file you're working on. That way Code knows about the .vscode directory and it's contents.

settings.json

  {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe",
            //"pythonPath": "C:/Users/khibma/AppData/Local/Programs/Python/Python37/python.exe", 
            //"pythonPath": C:/Python27/ArcGIS10.5/python.exe",
            "program": "${file}",
            "cwd": "${workspaceFolder}",
            "env": {},
            "envFile": "${workspaceFolder}/.env"
        },
        {
            "name": "Python: Terminal (integrated)",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "${config:python.pythonPath}",
            "program": "${file}",
            "cwd": "",
            "console": "integratedTerminal",
            "env": {},
            "envFile": "${workspaceFolder}/.env",
            "internalConsoleOptions": "neverOpen"
        }
    ]
}
Related Question