I am trying to learn more about Python in my spare time. I am a .net developer. I have downloaded a simple private open source project. The developer of the repository advised me to clone the repository and then run the project:
source .env/bin/activate
python3.6 ./project/main.py -c config.json
It works as expected. I am now thinking about debugging so that I can step through the code and debug it. Therefore I have downloaded Visual Studio Code and then installed the Python extension. I then start debugging and everything still works as expected. I opened the Visual Studio Code terminal and I see that Visual Studio Code runs the following:
bert@bertvb:~/myapp$ source /home/bert/myapp/.env/bin/activate
(.env) bert@bertvb:~/myapp$ /usr/bin/env /home/bert/myapp/.env/bin/python /home/bert/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/lib/python/debugpy/launcher 43369 -- /home/bert/myapp/myapp/main.py -c config.json
How does Visual studio Code know to run the first line i.e. to enter the virtual environment? I was advised that this would have to be run manually
Visual Studio Code automatically scans your workspace folder for any virtual environments. If it finds one, it will automatically enable it and select the Python interpreter installed in this virtual environment. If you want, you can disable this behaviour by setting the python.terminal.activateEnvironment option to false.
For more information, see the "Using Python environments in VS Code" documentation page, specifically the section "Where the extension looks for environments".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With