Here are five methods to create and manage Python virtual environments:
-
uv:
- Installation:
uvis a fast Python package installer that can also manage virtual environments. - Creating a Virtual Environment: To create a virtual environment using
uv, navigate to your project directory and run:This command creates a virtual environment in the current directory. citeturn0search5uv venv
- Activating the Virtual Environment: Activation is not required with
uv. You can run commands directly within the virtual environment using:This installs packages into theuv pip install <package_name>
uv-managed virtual environment. citeturn0search5
- Installation:
-
venv:
- Installation:
venvis included in the Python standard library for versions 3.3 and above. - Creating a Virtual Environment: Navigate to your project directory and run:
This creates a
python -m venv venv
.venvdirectory containing the virtual environment. citeturn0search2 - Activating the Virtual Environment:
- On macOS/Linux:
source venv/bin/activate - On Windows:
.venv\Scripts\activate
pip. - On macOS/Linux:
- Installation:
-
Pipenv:
- Installation: Install
Pipenvusingpip:pip install pipenv
- Creating a Virtual Environment: In your project directory, run:
This creates a
pipenv install
Pipfileand a virtual environment. citeturn0search1 - Activating the Virtual Environment: To activate the environment, run:
You can install packages using
pipenv shell
pipenv install <package_name>.
- Installation: Install
-
Poetry:
- Installation: Install
Poetryusing the recommended installation script:curl -sSL https://install.python-poetry.org | python3 - - Creating a Virtual Environment: In your project directory, initialize a new project:
This sets up a
poetry init
pyproject.tomlfile. citeturn0search14 - Activating the Virtual Environment: Poetry automatically manages virtual environments. To activate it, use:
Install packages with
poetry shell
poetry add <package_name>.
- Installation: Install
-
Conda:
- Installation: Download and install Anaconda or Miniconda from the official website.
- Creating a Virtual Environment: Create a new environment named
myenvwith Python:This sets up a new environment with the specified Python version. citeturn0search28conda create -p venv python==3.** -y - Activating the Virtual Environment: Activate the environment using:
Install packages using
conda activate myenv
conda install <package_name>.
