- Install Python (if not already installed)
Check if Python is installed:
python3 --version
If Python is not installed, download and install it from python.org.
- Create a Virtual Environment
Navigate to the directory where you want to create the virtual environment and run:
python3 -m venv myenv
Replace myenv with your desired virtual environment name.
- Activate the Virtual Environment
source myenv/bin/activate
Once activated, your terminal prompt will change, showing (myenv) before the command line.
- Deactivate the Virtual Environment
To exit the virtual environment, use:
deactivate
- Best practice location for Virtual Environments
Virtual environments are typically stored in your project directories. exmple init and activate below:
cd my_project
python3 -m venv venv
source venv/bin/activate