1 min read

Python Virtual Environments and pip

Virtual Environments

A virtual environment is a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

Creating a Virtual Environment

You can create a virtual environment using the venv module.

python -m venv myenv

Activating a Virtual Environment

On Windows, you can activate a virtual environment using the following command:

myenv\Scripts\activate.bat

On macOS and Linux, you can activate a virtual environment using the following command:

source myenv/bin/activate

pip

pip is the package installer for Python. You can use pip to install packages from the Python Package Index (PyPI).

Installing a Package

pip install requests

Uninstalling a Package

pip uninstall requests

Listing Installed Packages

pip list

programming/python/python