Open a Terminal:
Open a terminal window on your Linux system.
Navigate to your Project Directory:
Use the cd
command to navigate to the directory where you want to create your project and its virtual environment.
cd path/to/your/project
Create a Virtual Environment:
Run the following command to create a virtual environment. Replace venv
with the desired name for your virtual environment.
python3 -m venv venv
If you are using a version of Python prior to Python 3.3, you may need to install virtualenv
and then use it to create the virtual environment:
# Install virtualenv
pip install virtualenv
# Create a virtual environment
virtualenv venv
Activate the Virtual Environment:
Run this command :
source venv/bin/activate
After activation, your terminal prompt should change to indicate that you are now working within the virtual environment.
Install Dependencies:
Now that the virtual environment is active, you can install the project dependencies using pip
:
pip install package1 package2 ...
Replace package1
, package2
, etc., with the actual names of the packages your project requires.
Deactivate the Virtual Environment:
When you’re done working on your project, deactivate the virtual environment using the following command:
deactivate
Your terminal prompt should return to its normal state.
To work on your project in the future, you’ll need to reactivate the virtual environment by running the source venv/bin/activate
command again.
Comments
Post a Comment