@ gtracker64 gave me an easier way. Thank you very much.
There is also a way to set around python.pythonPath or python.venvPath in VSCode settings (setting.json). https://code.visualstudio.com/docs/python/environments
virtualenv
can create a Python virtual environment for each folder. I find it very useful. Visual Studio Code is usually used for front-end development, but it is quite convenient as long as you install Plugin as a Python IDE, with Lint, automatic source formatting, etc.
However, even if I enable the virtual environment with virtualenv
, when I open the source code with VSCode, I get various errors.
The reason VS Code doesn't recognize the Python virtual environment is that I don't know VS Code for the virtualenv environment variables enabled in source env / bin / activate
.
All you have to do is recognize the environment variables.
In a terminal, enable Python virtual completion and then launch VS Code from that terminal.
$ cd my-python-env
$ source my-python-env/bin/activate
$ code
If VS Code doesn't start when you run code
suddenly, you need to add the code command to the path.
As shown below, you can use a single command in VS Code.
When started this way, VS Code inherits all the environment variables in the terminal, so the Python virtual environment is also enabled.
It was surprisingly easy, but I was quite addicted to it. : sweat: