This guide provides step-by-step instructions to create and activate a Python virtual environment using virtualenv
.
- Ensure Python 3 is installed on your system. You can download it from the official Python website.
- Ensure
pip
is installed.pip
typically comes with Python, but you can install it separately if needed.
-
Install
virtualenv
:pip install virtualenv
-
Create a Virtual Environment:
virtualenv -p python3 env
This command creates a virtual environment named
env
using Python 3. -
Activate the Virtual Environment:
- For Linux/MacOS:
source env/bin/activate
- For Windows:
env\Scripts\activate
- For Linux/MacOS:
To deactivate the virtual environment, simply run:
deactivate
-
Installing Packages: Once the virtual environment is activated, you can install packages using
pip
as usual, e.g.,pip install package_name
-
Freezing Requirements: To freeze the installed packages into a
requirements.txt
file, use:pip freeze > requirements.txt
-
Installing from
requirements.txt
: To install packages from arequirements.txt
file, use:pip install -r requirements.txt
Abhishek Rajput
Palak Rajput