Skip to content

aatansen/Python-Dependency-Virtual-Environment-Managers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Dependency Virtual Environment Managers

Context

Top-Tier (Most Versatile & Recommended)

  • Fastest package installer and virtual environment manager.

⬆️ Go to Context

uv Installation

  • Using pip

    pip install uv
  • Using exe

    powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  • More installation process can be found in official docs

⬆️ Go to Context

uv Usage

uv venv   # Creates a .venv in the current directory
uv venv my_environment # Creates a venv named my_environment
uv venv --python 3.11.6  # Create venv with a specific Python version
uv pip install requests  # Install a package
uv pip list  # List installed packages
uv run app.py # to run py file

⬆️ Go to Context

More uv Commands

  • Activate environment

    .venv\Scripts\activate
  • Sync environment exactly to a requirements file (installs missing, removes extra)

    uv pip sync requirements.txt
  • Export to requirements.txt

    uv export --format requirements-txt --no-hashes --no-annotate > requirements.txt
  • Adding packages to uv from requirements.txt

    uv init
    uv add -r requirements.txt
  • Upgrade packages

    uv lock --upgrade-package requests

    or all packages

    uv lock --upgrade
    • Now run uv sync
  • Initialize a new project (creates pyproject.toml)

    uv init
  • Add dependencies to pyproject.toml and install/sync them

    uv add flask requests
  • Add a development dependency

    uv add --group dev pytest
  • Remove a dependency

    uv remove requests
  • Create/update the uv.lock file based on pyproject.toml

    uv lock
  • Install dependencies into the venv based on uv.lock (like uv pip sync)

    uv sync
  • Display Dependency Tree

    uv tree
  • Use pip command in uv environment by installing seed packages (one or more of: pip, setuptools, and wheel) into the virtual environment.

    uv venv --seed
  • ModuleNotFoundError: No module named 'distutils'

  • pip install setuptools will solve this error

⬆️ Go to Context

Minimal requirements.txt

  • Install pipdeptree

    uv pip install pipdeptree
  • Run the command to generate indented requirements.txt

    pipdeptree -f > requirements.txt
  • Package can be excluded

    pipdeptree --exclude pip,pipdeptree,setuptools,wheel,build,packaging,pyproject_hooks -f > requirements.txt
  • Minimal only main package requirements.txt

    pipdeptree --warn silence | grep -E "^[a-zA-Z0-9]" | awk '{print $1}' > requirements.txt

    or

    pipdeptree --warn silence | findstr "^[a-zA-Z]" > requirements.txt
  • Combined exclude and minimal command

    pipdeptree --exclude pip,pipdeptree,setuptools,wheel,build,packaging,pyproject_hooks  --warn silence | grep -E "^[a-zA-Z0-9]" | awk '{print $1}' > requirements.txt
  • Upgrade package version in requirements.txt using pur

    pur -r requirements.txt

⬆️ Go to Context

  • Full-fledged dependency and package manager.

⬆️ Go to Context

poetry Installation

curl -sSL https://install.python-poetry.org | python3 -

Using pip

pip install poetry

⬆️ Go to Context

poetry Usage

  • Create pyproject.toml

    poetry init
  • Or create a peotry project

    poetry new project_name
  • Create virual environment (env will be create in cache directory)

    poetry install
  • To create virtual environment withing project directory

    poetry config virtualenvs.in-project true

    Then

    poetry install
  • Add a package

    poetry add requests
  • Remove a package

    poetry remove flask

⬆️ Go to Context

More poetry Commands

  • Show install packages

    poetry show
  • Show details of a specific package

    poetry show flask
  • Update all dependencies

    poetry update
  • Lock dependencies (generate/update poetry.lock)

    poetry lock
  • Run command inside the virtual environment

    poetry run python new.py
  • List all virtual environments

    poetry env list
  • Check for dependency issues

    poetry check

⬆️ Go to Context

  • Best for managing multiple Python versions and virtual environments.

⬆️ Go to Context

pyenv Installation

  • Using pip

    pip install pyenv-win --target %USERPROFILE%\\.pyenv
  • If you run into an error with the above command use the following instead (#303):

    pip install pyenv-win --target %USERPROFILE%\\.pyenv --no-user --upgrade
  • Setup Windows environment variable

    Variable Value
    PYENV C:\Users\my_pc.pyenv\pyenv-win\
    PYENV_HOME C:\Users\my_pc.pyenv\pyenv-win\
    PYENV_ROOT C:\Users\my_pc.pyenv\pyenv-win\
  • And add two more lines to user variable Path

    C:\Users\my_pc\.pyenv\pyenv-win\bin
    C:\Users\my_pc\.pyenv\pyenv-win\shims
  • Restart cmd or run RefreshEnv.cmd command provided by Chocolatey

⬆️ Go to Context

pyenv Usage

  • Get list of available python version

    pyenv install -l
  • Installing a python version

    pyenv install 3.10.5
  • Uninstalling a python version

    pyenv uninstall 3.10.5
  • Set python

    pyenv global 3.10
  • Select just for current shell session

    pyenv shell 3.10.5
  • Multiple Python versions at the same time by specifying multiple arguments

    pyenv global 3.11 3.12
  • pyenv update python version

    pyenv update

⬆️ Go to Context

  • Best for installing standalone CLI tools globally in isolated environments.

⬆️ Go to Context

pipx Installation

  • Installing using pip

    python -m pip install --user pipx
  • Warning solution

    WARNING: The scripts activate-global-python-argcomplete.exe, python-argcomplete-check-easy-install-script.exe and register-python-argcomplete.exe are installed in 'C:\Users\Admin\AppData\Roaming\Python\Python312\Scripts' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    WARNING: The script userpath.exe is installed in 'C:\Users\Admin\AppData\Roaming\Python\Python312\Scripts' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    WARNING: The script pipx.exe is installed in 'C:\Users\Admin\AppData\Roaming\Python\Python312\Scripts' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
    
  • Go to mentioned path C:\Users\Admin\AppData\Roaming\Python\Python312\Scripts

  • Open cmd on that path and run

    .\pipx.exe ensurepath

⬆️ Go to Context

pipx Usage

  • Installing Package

    pipx install pycowsay
  • Uninstalling Package

    pipx uninstall pycowsay
  • Inject a package (when required additional packages)

    pipx inject ipython matplotlib
  • Injecting multiple packages

    pipx inject ipython matplotlib pandas
    # or:
    pipx inject ipython -r useful-packages.txt

⬆️ Go to Context

CLI tools to try in pipx

Tool Purpose Use Case
httpie HTTP client User-friendly curl alternative for APIs
black Code formatter Opinionated Python formatter (fast + safe)
ruff Linter + Formatter All-in-one linting (super fast, written in Rust)
poetry Package manager Modern dependency management + publishing
pipenv Package manager Dependency locking + venv in one
cookiecutter Project scaffolding Generate project boilerplates
rich-cli Pretty CLI output Render JSON, markdown, syntax-highlighted code
glances System monitor Real-time system resource viewer (cross-platform)
pgcli PostgreSQL client Auto-complete + syntax highlighting in terminal
bpython Python REPL Fancy REPL with autocomplete & docs
ipython Advanced REPL Interactive dev console with magic commands
howdoi Quick answers Searches StackOverflow from terminal
doit Task runner Better alternative to Makefiles for Python projects
pdm Next-gen package manager PEP 582 support (no venv needed)
xonsh Shell + Python Shell with full Python power
yt-dlp YouTube downloader Download and convert videos via CLI

⬆️ Go to Context

  • It is a fast, multi-language package and environment manager built on top of the Conda ecosystem.

pixi Installation

  • Run the powershell command

    powershell -ExecutionPolicy ByPass -c "irm -useb https://pixi.sh/install.ps1 | iex"

⬆️ Go to Context

pixi Environment Setup on VSCode

I found an issue while working on jupyter notebook with multiple pixi environment, when I tried to select kernel it does not allow to select manually it only allows the auto listed ones, to solve this issue I tried some extension and found a good one that actually work which is Pixi Code by renan-r-santos

  • It will auto detect the parent virtual environment

  • To work with multiple environment we can either use the python environment tab and select it from there or create a .vscode folder and inside this folder a file named settings.json and write the following structure to find that specific environment in the jupyter kernel

    {
      "python-envs.pythonProjects": [
        {
          "path": "Module 32 - Feature Engineering/Day 61 - Handling Missing Data/.pixi",
          "envManager": "ms-python.python:venv",
          "packageManager": "ms-python.python:pip"
        }
      ]
    }

Note

  • There are some issue when first time running the cell
  • getActivatedEnvironmentVariables Error to solve it just restart the kernel and run the cell again
  • Or use the python environment tab and select the one refers in settings.json it will be more faster

⬆️ Go to Context

pixi Usage

  • Initial pixi

    pixi init
  • Create environment

    pixi install
  • Add package

    pixi add 'python>=3.13.0,<3.14' jupyterlab
  • Add package (when package not available in conda channels --pypi is used)

    pixi add django --pypi
  • Add packages from requirements.txt

    • Create a file add_to_pixi.cmd

      @echo off
      REM -----------------------------
      REM Install packages from requirements.txt using Pixi
      REM Automatically adds --pypi if default install fails
      REM -----------------------------
      
      SETLOCAL ENABLEDELAYEDEXPANSION
      SET "FILE=requirements.txt"
      
      FOR /F "usebackq delims=" %%A IN ("%FILE%") DO (
          REM Get package name without version
          FOR /F "tokens=1 delims==" %%B IN ("%%A") DO (
              echo Installing %%B...
              pixi add %%B
              IF !ERRORLEVEL! NEQ 0 (
                  echo "Failed to install %%B via default, trying with --pypi..."
                  pixi add %%B --pypi
              )
          )
      )
      
      echo All packages processed!
      pause
    • Now run add_to_pixi.cmd

  • Remove package

    pixi remove django --pypi
  • Remove pixi environment

    pixi clean
  • List all install packages

    pixi list
  • Activate environment shell

    pixi shell
  • Exit environment shell

    exit
  • Run command

    pixi run python --version
    pixi run jupyter lab

⬆️ Go to Context

Mid-Tier (Popular & Well-Supported)

  • Default, lightweight, and comes with Python.

⬆️ Go to Context

pip Installation

  • It is installed by default with Python >= 3.4

  • Update pip

    python -m pip install pip --upgrade

⬆️ Go to Context

pip Usage

  • Installing a package

    pip install <package-name>
  • Installing specific version

    pip install <package-name>==<version>
  • Installing from a requirements file

    pip install -r requirements.txt
  • Saving current packages to a requirements file

    pip freeze > requirements.txt
  • Updating multiple packages

    pip install -r requirements.txt --upgrade
  • Uninstalling a package

    pip uninstall <package-name>
  • Listing installed packages

    pip list
  • Checking outdated packages

    pip list --outdated
  • Showing info about a package

    pip show <package-name>

⬆️ Go to Context

venv Usage

  • It is added in 3.3 python

  • Official docs

  • Creating a virtual environment

    py -m venv env

    here env is the name of the venv also path can be provided here

  • Activating the virtual environment

    env\Scripts\activate
  • Deactivating the virtual environment

    deactivate
  • Deleting a virtual environment

    rd /s /q env
  • Check all available python

    py -0
  • Specify alternative Python executable

    C:\Python312\python.exe -m venv .venv
  • Create venv with different python version (PYLAUNCHER_ALLOW_INSTALL permission required)

    py -3.12 -m venv .venv
  • Create multiple venv

    py -m venv env1 env2 env3
  • venv command-line option(flags)

    • Upgrade existing venv

      py -m venv --upgrade .venv
    • Upgrade pip setuptools

      py -m venv --upgrade-deps .venv
    • Without pip

      py -m venv --without-pip .venv
    • For advanced usage --copies, --symlinks are used but not recommended on Windows

    • Custom prompt name

      py -m venv --prompt myproject .venv
    • Clear existing environment

      py -m venv --clear .venv
    • Create environment with access to system packages

      py -m venv --system-site-packages .venv

⬆️ Go to Context

  • It is a minimal, community-driven Conda distribution that includes both the conda and mamba package managers, with the conda-forge channel set as the default source for packages.
  • Ideal for data science and scientific computing. It manages packages, environments, and dependencies effectively across platforms.
  • Since it is included with Miniforge3, there is no need to install it separately. However, if needed, download and install Miniconda (a lightweight Conda distribution) or Anaconda (which includes many pre-installed packages).

conda Usage

Task Command
Env in miniconda envs path conda create -n myenv python=3.11
Env in current path conda create -p myenv python=3.11
Activate environment conda activate myenv
Deactivate environment conda deactivate
List all environments conda env list or conda info --envs
Install package conda install numpy
Install specific version conda install pandas=1.5.3
Remove package conda remove package_name
Update package conda update scipy
Update all package conda update --all
Export environment conda env export > environment.yml
Recreate env from file conda env create -f environment.yml
Delete environment conda remove --name myenv --all
  • Install packages from requirements.txt

    conda install --yes --file requirements.txt

Note

  • Prefer conda install when available to avoid dependency conflicts.

  • Use pip install within a conda environment if a package isn't available via conda.

⬆️ Go to Context

  • It is a fast, drop-in replacement for conda written in C++
  • It is included by default in Miniforge versions 23.3.1-0 and above.
  • All commands are compatible with conda, so simply replacing conda with mamba will work seamlessly.

⬆️ Go to Context

  • Modern package and virtual environment manager.

⬆️ Go to Context

hatch Installation

  • Installer
  • Using pipx
    • pipx install hatch

⬆️ Go to Context

hatch Usage

  • Create hatch project

    hatch new hatch-project
  • Create environment

    hatch env create
  • Activate and use the environment

    hatch shell
  • Exit from environment

    exit
  • Remove environment

    hatch env prune
  • View list of environment

    hatch env show
  • Project version check

    hatch version
  • Change project version

    hatch version minor # patch, minor, major

⬆️ Go to Context

  • Alternative to venv with more features.

⬆️ Go to Context

virtualenv Installation

  • Using pipx

    pipx install virtualenv

⬆️ Go to Context

virtualenv Usage

  • Creating env

    virtualenv env
  • Activating env

    env\Scripts\activate
  • Deactivate env

    deactivate

⬆️ Go to Context

Lower-Tier (Less Commonly Used)

  • Universal version manager supporting Python and other languages.

⬆️ Go to Context

  • Helper for managing virtualenv environments easily.

⬆️ Go to Context

virtualenvwrapper Installation

  • Using pipx

    pipx install virtualenvwrapper-win

⬆️ Go to Context

virtualenvwrapper Usage

Purpose Command
Create & activate a new virtualenv mkvirtualenv myenv
List or activate virtualenvs workon myenv
Delete a virtualenv rmvirtualenv myenv
Go to the directory of the current env cdvirtualenv
Go to site-packages of current env cdsitepackages
List packages installed in current env lssitepackages
List all virtualenvs lsvirtualenv
Add folders to PYTHONPATH of active env add2virtualenv path\to\folder
Allow/disallow global packages in current env toggleglobalsitepackages
Create a project directory and virtualenv mkproject myproject
Go to the directory of the current project cdproject
Link a project directory to the current virtualenv setprojectdir D:\myproject
Used internally for deletion folder_delete D:\Env\myenv
Locate the current virtualenv's base directory whereis
Lists env variables for the current env vwenv

⬆️ Go to Context

  • Minimalistic package builder and publisher.

⬆️ Go to Context

flit Installation

  • Using pipx

    pipx install flit

⬆️ Go to Context

flit Usage

  • Initial project

    flit init
  • Publish package to PyPI

    flit publish

⬆️ Go to Context

About

Python dependency and virtual environment managers. I have tried most of them and ranked them based on my use cases, from uv, Poetry, and pipx to classics like virtualenv, venv, and conda.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages