How to activate virtualenv in Linux?
To activate a virtual environment in Linux, you can use the source
command and the path to the activate
script that is located in the virtual environment's bin
directory.
Here's an example of how you can activate a virtual environment called myenv
:
# Navigate to the directory where the virtual environment is located
cd /path/to/virtualenvs/myenv
# Activate the virtual environment
source bin/activate
This will activate the virtual environment and change the prompt to indicate that the virtual environment is active. The name of the virtual environment will be displayed in parentheses at the beginning of the prompt.
While the virtual environment is active, any Python packages that you install will be installed in the virtual environment, and they will only be available within the virtual environment.
To deactivate the virtual environment, you can use the deactivate
command:
# Deactivate the virtual environment
deactivate
This will deactivate the virtual environment and return you to the global Python environment.