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/projectCreate 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 venvIf 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 venvActivate the Virtual Environment:
Run this command :
source venv/bin/activateAfter 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:
deactivateYour 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