Issue
I have django project folder with venv environment. when opening vscode it has terminal opened in vscode.
Is there a way that I don't have to venv/bin/activate all the time when opening the project folder?
Solution
Edit (credit to @XJOJIX) from the comment in this answer. This will active the virtual environment without having to close or open terminals. A Python file still needs to be selected to load the Python extension.
Add this parameter in VS Code to "launch.json" or ".code-workspace"
"settings": {
"python.terminal.activateEnvInCurrentTerminal": true
}
Previous Answer:
To have a VS Code terminal automatically activate a virtual environment when first launching VS Code:
- Close the terminal before exiting VS Code.
- Open VS Code. Ensure a Python file is selected to direct VS Code to load the Python extension.
- Wait for the Python extension to finishing loading (very bottom left of VS Code terminal).
- Open a new terminal after Python extension has loaded. The venv will automatically activate.
The trick is to open the terminal only after the Python extension has loaded.
If the directory of the terminal contains a virtual environment, VS Code will also automatically activate a virtual environment if a new terminal is opened. As before, a Python file must be selected and the Python extension must be fully loaded.
Answered By - Jason Cook
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.