virtualenv
virtualenv is a tool for creating isolated Python environments, allowing developers to manage dependencies for different projects separately. The current version is 21.2.0, with regular updates to enhance functionality and maintain compatibility with Python versions.
Warnings
- breaking virtualenv 21.0.0 refactored the discovery module, which may affect custom scripts relying on internal APIs.
- deprecated The --relocatable option is experimental and may not work in all circumstances.
- gotcha Creating a virtual environment without specifying the Python version may result in using an unintended interpreter.
- gotcha System-wide PYTHONPATH settings can interfere with virtualenv's isolation.
- gotcha Moving a virtual environment directory can break its functionality due to absolute paths.
Install
-
pip install virtualenv
Quickstart
import os
# Create a virtual environment
os.system('virtualenv myenv')
# Activate the virtual environment
if os.name == 'nt':
os.system('.\\myenv\\Scripts\\activate')
else:
os.system('source myenv/bin/activate')
# Install a package within the virtual environment
os.system('pip install requests')
# Deactivate the virtual environment
os.system('deactivate')