A tool for creating isolated 'virtual' python environments
npx @tessl/cli install tessl/pypi-virtualenv@16.7.0A comprehensive tool for creating isolated Python virtual environments that enable developers to manage dependencies and Python versions per project without conflicts. Virtualenv offers command-line functionality for creating, activating, and managing virtual environments with support for different Python interpreters, custom site-packages directories, and environment isolation features.
pip install virtualenvimport virtualenvFor programmatic usage:
from virtualenv import create_environment, main# Create a virtual environment
virtualenv myenv
# Create with specific Python version
virtualenv --python=python3.8 myenv
# Create with system site-packages access
virtualenv --system-site-packages myenv
# Clear and recreate environment
virtualenv --clear myenvimport virtualenv
# Create a basic virtual environment
virtualenv.create_environment('/path/to/myenv')
# Create with custom options
virtualenv.create_environment(
'/path/to/myenv',
site_packages=True, # Include global site-packages
clear=True, # Clear existing environment
prompt='myproject', # Custom prompt
no_pip=False, # Install pip
no_setuptools=False, # Install setuptools
no_wheel=False, # Install wheel
symlink=True # Use symlinks instead of copying
)Virtualenv is designed as a single-module package with the following key components:
The package provides both command-line and programmatic interfaces, making it suitable for interactive use and integration into automated deployment workflows.
Primary interface for creating and configuring virtual Python environments with extensive customization options including Python interpreter selection, package isolation controls, and dependency management.
def create_environment(
home_dir,
site_packages=False,
clear=False,
prompt=None,
search_dirs=None,
download=False,
no_setuptools=False,
no_pip=False,
no_wheel=False,
symlink=True
):
"""
Creates a new environment in home_dir.
Parameters:
- home_dir (str): Target directory for the virtual environment
- site_packages (bool): Include global site-packages in environment
- clear (bool): Clear existing environment before creating
- prompt (str): Custom prompt prefix for the environment
- search_dirs (list): Directories to search for packages
- download (bool): Download packages if not found locally
- no_setuptools (bool): Skip installing setuptools
- no_pip (bool): Skip installing pip
- no_wheel (bool): Skip installing wheel
- symlink (bool): Use symlinks instead of copying files
Returns:
None
"""
def main():
"""
Command-line interface entry point.
Parses command-line arguments and creates virtual environment
based on provided options. Uses sys.argv for argument parsing.
Returns:
None (exits process)
"""Helper functions for path resolution, file system operations, and environment introspection that support the core virtualenv functionality.
def path_locations(home_dir, dry_run=False):
"""
Calculate standard path locations for a virtual environment.
Parameters:
- home_dir (str): Virtual environment directory
- dry_run (bool): Whether this is a dry run
Returns:
tuple: (home_dir, lib_dir, inc_dir, bin_dir)
"""
def is_executable_file(fpath):
"""
Check if a file path is an executable file.
Parameters:
- fpath (str): File path to check
Returns:
bool: True if file exists and is executable
"""
def resolve_interpreter(exe):
"""
Resolve Python interpreter path from name or path.
Parameters:
- exe (str): Python executable path or name
Returns:
str: Resolved absolute path to interpreter
"""Comprehensive file and directory manipulation functions for environment setup, including copying, linking, and permission management with cross-platform compatibility.
def copy_file_or_folder(src, dest, symlink=True):
"""
Copy file or folder with symlink support.
Parameters:
- src (str): Source path
- dest (str): Destination path
- symlink (bool): Use symlinks when possible
Returns:
None
"""
def mkdir(at_path):
"""
Create directory if it doesn't exist.
Parameters:
- at_path (str): Directory path to create
Returns:
None
"""
def rm_tree(folder):
"""
Remove directory tree recursively.
Parameters:
- folder (str): Directory path to remove
Returns:
None
"""class Logger:
"""
Logging object for command-line script with level-based output control.
Class Constants:
- DEBUG: Debug level messages
- INFO: Informational messages
- NOTIFY: Important notifications (between INFO and WARN)
- WARN/WARNING: Warning messages
- ERROR: Error messages
- FATAL: Fatal error messages
Methods:
- debug(msg, *args, **kw): Log debug message
- info(msg, *args, **kw): Log info message
- notify(msg, *args, **kw): Log notification message
- warn(msg, *args, **kw): Log warning message
- error(msg, *args, **kw): Log error message
- fatal(msg, *args, **kw): Log fatal message
- start_progress(msg): Start progress indicator
- end_progress(msg): End progress indicator
"""
class ConfigOptionParser:
"""
Extended OptionParser with configuration file support.
Inherits from optparse.OptionParser and adds ability to read
configuration from INI files and environment variables.
"""
class FileView:
"""
File viewing utility for binary file operations.
Provides windowed access to file contents for reading and
modifying specific portions of binary files.
"""__version__: str # Package version string ("16.7.11" - note: differs from package tag)
virtualenv_version: str # Legacy alias for __version__IS_WIN: bool # True if running on Windows
IS_CYGWIN: bool # True if running on Cygwin
IS_DARWIN: bool # True if running on macOS
IS_PYPY: bool # True if running on PyPy interpreter
VERSION: str # Current Python version (e.g., "3.8.10")
PY_VERSION: str # Python version with prefix (e.g., "python3.8")DEFAULT_STORAGE_DIR: str # Default storage directory for virtualenv files
DEFAULT_CONFIG_FILE: str # Path to default configuration file
USER_DIR: str # User's home directory