How do I install virtual venv in VS code?

How do I install virtual venv in VS code?

In Visual Studio Code (VS Code), you don't actually "install" a virtual environment; rather, you create and activate a virtual environment using the terminal integrated into VS Code. Here are the steps to create and activate a virtual environment in VS Code:

  1. Install Python: Make sure you have Python installed on your machine. You can download it from the official Python website. During the installation process, make sure to check the option to add Python to your system PATH.

  2. Open a New Terminal: Open VS Code and open a new terminal. You can do this by selecting "View" in the top menu and then choosing "Terminal" or by using the keyboard shortcut Ctrl + `.

  3. Navigate to Your Project Directory: Use the cd command to navigate to the directory where you want to create your virtual environment.

     cd path/to/your/project
  4. Create a Virtual Environment: Run the following command to create a virtual environment. This example uses the venv module, which is included with Python 3.3 and later versions.

     python -m venv venv

    This command creates a folder named venv in your project directory, containing the virtual environment.

  5. Activate the Virtual Environment: Depending on your operating system, the activation command will differ:

    • On Windows:

    • On macOS/Linux:

        source venv/bin/activate

After activation, you should see the name of your virtual environment in the terminal prompt.

  1. Verify Activation: You can verify that your virtual environment is active by checking the terminal prompt for the virtual environment name or by running the following command:

     which python

    It should point to the venv directory.


Now, you have successfully created and activated a virtual environment in VS Code. You can install and manage Python packages within this isolated environment for your project.

Did you find this article valuable?

Support LingarajTechhub All About Programming by becoming a sponsor. Any amount is appreciated!