2

Recently I've been using pyenv-virtualenv for my python projects and with the vscode extension "Python Environment Manager", and I love the combo.

However I currently need to activate the virtualenvs manually through the plugin.

Does anyone know if there's a good way and have tested it to do it automatically?

Can I for for example create some kind of file structure that would allow vscode to automatically select the right pyenv-virtualenv when I open a file in a specific repo/folder?

rioV8
  • 24,506
  • 3
  • 32
  • 49
wartock
  • 21
  • 1

2 Answers2

0
  • Open a folder as a workspace

  • Use the command to create a new virtual environment in the terminal,

    enter image description here

    The above command will generate a .venv folder in the current workspace, which is a virtual environment named .venv

  • Select the .venv virtual environment interpreter in the Select Interpreter panel

    enter image description here

  • New terminals will automatically activate the environment

    enter image description here

When you open this folder with vscode next time, VScode will select the last interpreter by default. If you have not changed it, then you will select the .venv virtual environment by default when you open this folder in the future.

JialeDu
  • 6,021
  • 2
  • 5
  • 24
0

I've found that if I configure the Python: Venv Path setting to the location of my pyenv folder it will automatically pick the correct virtual environment. Although I always open VS Code from a terminal using code ..

enter image description here

Liedakkala
  • 388
  • 1
  • 3
  • 12