3

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!

7

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"
        }
    ]
}
6
  • Ok, I added the above paths and copied your json settings, modifying the paths to reflect my own computer directory settings. In the bottom left-hand corner it now says Python 3.6.8 64-bit, so it did something. However, when I type import arcpy into the Python shell in the terminal window I still get the "no module named arcpy". Why is this the case? – Dianne Gray May 5 '20 at 15:36
  • At the terminal window you dont have access to arcpy because the terminal is using the system path, not a path from Code itself. And you do not have a reference within your system Path to ArcGIS Pro conda's Python. If its loading up some Python, odds are it is not a Python version associated with ArcGIS. If you type path at the prompt, you should be able to see where it's finding Python from. – KHibma May 5 '20 at 17:00
  • Ah I see, so there's no way to change the source path for the terminal? Is this the case with all IDE programs? If this is the case, I suppose using the built-in Python shell within ArcGIS Pro is the best way to test segments of arcpy code? – Dianne Gray May 5 '20 at 17:17
  • You could set your system Path and re-start VS Code. That should do it – KHibma May 5 '20 at 17:45
  • How do I set the System Path? Would the System Path also be C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe? – Dianne Gray May 21 '20 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.