Home > Net >  How can I activate my virtualenv in visual code terminal?
How can I activate my virtualenv in visual code terminal?

Time:07-16

How can I activate my virtual environment in visual code terminal? I've tried using the workspace settings method but the settings file was empty

CodePudding user response:

If you have already created your virtual environment, you can just go to its directory by running the following in the VS Code terminal:

cd /python_env/bin/

and then

source ./activate

or, you can directly run

source ./python_env/bin/activate

from your main project directory.

CodePudding user response:

Please follow the steps below:

  1. Open your project folder in VS Code

  2. Create a new terminal

  3. Use the following command in the terminal to create a new virtual environment

    # .venv is your virtual environment name
    # You can also use py -3 -m venv .venv
    python -m venv .venv
    
  4. After the virtual environment is generated, use the following command to activate the virtual environment

    # .venv is your virtual environment name
    .venv\scripts\activate
    

Normally, when VS Code notices that you have created a new virtual environment, a popup will prompt you to allow it to be selected for the workspace.

enter image description here

  • Related