Cursor cannot detect different venvs based on directory

Is it possible to point Cursor/VSCode to a different python interpreter depending on file / directory location?

Our folder setup is as follows:

  • /repo-root/
  • /repo-root/app/
  • /repo-root/app/foo/
  • /repo-root/app/bar/
  • /repo-root/app/baz/

foo, bar, and baz require distinct venvs / interpreters (all files within these directories use app’s venv). My interpreters/venvs are currently installed via pyenv at various locations, ie ~/.pyenv/versions/foo/bin/python or ~/.pyenv/versions/bar/bin/python

How can I let Cursor know to use the correct interpreter based on which file I’m working on? I can manually select the interpreter via dropdown on bottom right, but I hope I can tell Cursor about these automatically. This is possible in my current main IDE, JetBrains

Things I’ve tried

  • Added a .pyrightconfig.json in each app directory with key “venvPath” pointing to correct venv
  • creating a .env file with PYTHONPATH=<path to app’s venv> in each app diretory
  • creating a .vscode/settings.json file in each app with key “python.defaultInterpreterPath” pointing to venv
    Restarted after each change

None of these currently work

1 Like

Any update on this? Still seeing this issue

This worked for me and maybe it will work for you:

  1. Open Command Palette:
  • Press Ctrl+Shift+P (or Cmd+Shift+P on macOS).
  1. Select Python Interpreter:
  • Search for Python: Select Interpreter.
  • A list of Python interpreters will appear. Select the one corresponding to your venv folder

Ya I can manually switch interpreters, but it doesn’t switch automatically based on the directory the file belongs to

1 Like

Ran into the same problem. When using the “select interpreter” my venv was not in the list. But I could specify the directory and then select the python executable in the venv folder.

1 Like