/venv

Venv commands

Apache License 2.0Apache-2.0

venv

Venv commands To use Python virtual environments (virtualenv) in Linux, follow these steps:

  1. Open a terminal window.

  2. Install virtualenv package if you don't have it already. Run the following command:

pip install virtualenv
  1. Create a new virtual environment. Navigate to the desired directory and run the following command:
virtualenv -p python3 (or the path to the python we wish to be using) <my_env_name>

Replace myenv with the desired name for your virtual environment.

  1. Activate the virtual environment by running the activation script. Use the following command:
source myenv/bin/activate

Once activated, you should see the name of the virtual environment (myenv) at the beginning of the command prompt.

  1. Install packages and work with your Python project as usual. Any packages you install will be isolated within the virtual environment.

  2. When you're done working within the virtual environment, you can deactivate it. Simply run the following command:

deactivate

The virtual environment will be deactivated, and you will return to your system's default Python environment.

Using a virtual environment allows you to isolate dependencies for different projects, avoiding conflicts and ensuring project-specific package versions. You can create and activate multiple virtual environments as needed for different projects.