0

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.

user44796
  • 1,053
  • 1
  • 11
  • 20
  • Did you set the interpreter via the "Command Palette"? – JonSG May 19 '23 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. – user44796 May 19 '23 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. – JonSG May 19 '23 at 13:41
  • I have already done this, but it is a good suggestion. – user44796 May 19 '23 at 14:59
  • You can read [document](https://code.visualstudio.com/docs/python/environments#_working-with-python-interpreters) for more details. – MingJie-MSFT May 22 '23 at 01:24
  • I don't have anything else to add. As I said before, when I open VSCode from a shortcut, it shows the the correct environment is loaded, but when I open python in the terminal, a different interpreter is used (probably read from PYTHONPATH, I am guessing). When I open VSCode from within a command prompt with anaconda, it works. – user44796 May 26 '23 at 19:52
  • I don't think it is really a solution, as VSCode is still not functioning properly. It is pointing to the correct interpreter, but opening another version of python when called within a terminal. – user44796 May 31 '23 at 12:03

3 Answers3

0

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:

smoot
  • 21
  • 5
  • 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. – user44796 May 19 '23 at 14:46
  • When you’re in a terminal what does the command ‘which Python’ return? – smoot May 20 '23 at 15:44
  • It raises the error that the term is not recognized. – user44796 May 31 '23 at 12:02
0

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.

0

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

user44796
  • 1,053
  • 1
  • 11
  • 20