Answer a question

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?

Answers

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:

  1. Close the terminal before exiting VS Code.
  2. Open VS Code. Ensure a Python file is selected to direct VS Code to load the Python extension.
  3. Wait for the Python extension to finishing loading (very bottom left of VS Code terminal).
  4. 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.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐