13

I am using VSCode with ArcGIS Pro 3.0 in a virtual environment. Until yesterday, everything worked just fine. After updating to Pro 3.0, I was still able to use open a script and then have it run in the terminal window.

Previously, I was able to select a line from the script, run it, and then it would open the correct interpreter. However, now I am unable to do so and cannot troubleshoot why this is happening. I have added the correct path to the ArcGIS Pro python executable in the interpreter path, but the terminal opens to another python executable. Any advice would be greatly appreciated as to how I can run specific python executable that I want to run.

UPDATE: I can open VSCode using code from my anaconda installation, but still am having trouble running python interactively in the terminal. Previously, I used to be able to do this (e.g. test indented code cells), but this doesn't seem to be functioning anymore.

7
  • Did you set the interpreter via the "Command Palette"? Commented May 19, 2023 at 13:05
  • I set the interpreter via settings. In the command palette, it shows the correct interpreter, but "recommends" another one. When the terminal window opens, it doesn't open up python, and when I type "python" it opens the recommended python interpreter. A workaround for now is to open VSCode via "code" in an anaconda environment. Commented May 19, 2023 at 13:39
  • Ah, then you likely need update your path to point to the python you are interested in using as the terminal is using an env that points to the new install. Commented May 19, 2023 at 13:41
  • I have already done this, but it is a good suggestion. Commented May 19, 2023 at 14:59
  • You can read document for more details. Commented May 22, 2023 at 1:24

3 Answers 3

22

You should be able to point VSCode to a specific python interpreter in a virtual environment - you can access this via View > Command Palette > Python: Select Interpreter

Select Interpreter Window

Then once you open a .py file you should see the python interpreter in the bottom right portion of the window, and if you open a new terminal it will use that specified interpreter

Some other references:

Sign up to request clarification or add additional context in comments.

3 Comments

I can get to this point. However, even though the lower right bar shows the correct anaconda environment, when I open up a new terminal it is in powershell (as before) and previously when I ran a line of python code, it automatically opened up the correct interpreter. Now, VSCode just issues a warning and I have to manually type python in the terminal. This starts the "recommended" python, not the one linked to in the interpreter path.
When you’re in a terminal what does the command ‘which Python’ return?
It raises the error that the term is not recognized.
2

To select a specific Python interpreter with ArcGIS Pro 3.0 within a virtual environment in Visual Studio Code (VSCode), you can follow these steps:

  1. create a virtual environment. ArcGIS Pro 3.0 comes with its own Python installation, you need to ensure that the virtual environment is set up correctly to use that Python version.

    python -m venv myenv

  2. Activate the virtual environment. on windows: myenv\Scripts\activate on macos : myenv/bin/activate

  3. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS) to open the Command Palette.

  4. Type Python select interpreter and press Enter.

  5. In the list of available interpreters, you should see the Python interpreter from your virtual environment. It might be named something like "myenv".

  6. Select the desired Python interpreter from the list

now you will get your desired interpreter.

Comments

0

I was typing python instead of Python. python was engaging python that was in PYTHONPATH.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.