| name | python-env |
| description | Python environment management with venv, Poetry, Pipenv, pyenv, and conda. Use when user asks to "create virtual environment", "set up Poetry", "manage Python versions", "fix pip issues", "install dependencies", "create requirements.txt", or any Python environment tasks. |
Python Environment Management
Virtual environments, dependency management, and Python version control.
venv (Built-in)
python -m venv .venv
python3 -m venv .venv
source .venv/bin/activate
.venv\Scripts\activate
deactivate
pip install requests flask
pip install -r requirements.txt
pip freeze > requirements.txt
pip install --upgrade pip
requirements.txt
# Pinned versions (production)
flask==3.0.0
requests==2.31.0
sqlalchemy==2.0.23
# Ranges (library development)
flask>=3.0,<4.0
requests~=2.31 # Compatible release (>=2.31, <3.0)
# With extras
fastapi[all]==0.104.0
# From git
git+https://github.com/user/repo.git@main#egg=package
pip install -r requirements.txt
pip install -r requirements-dev.txt
Poetry
curl -sSL https://install.python-poetry.org | python3 -
poetry new my-project
poetry init
poetry add requests flask
poetry add pytest --group dev
poetry add "sqlalchemy>=2.0,<3.0"
poetry remove requests
poetry install
poetry install --without dev
poetry update
poetry update requests
poetry show
poetry show --tree
poetry run python main.py
poetry run pytest
poetry shell
poetry build
poetry publish
poetry export -f requirements.txt --output requirements.txt
poetry export -f requirements.txt --without-hashes
pyproject.toml (Poetry)
[tool.poetry]
name = "my-project"
version = "1.0.0"
description = "My project"
authors = ["Name <email@example.com>"]
python = "^3.11"
[tool.poetry.dependencies]
python = "^3.11"
flask = "^3.0"
sqlalchemy = "^2.0"
[tool.poetry.group.dev.dependencies]
pytest = "^8.0"
ruff = "^0.1"
mypy = "^1.7"
[tool.poetry.scripts]
serve = "my_project.main:app"
uv (Fast Python Package Manager)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
uv pip install requests flask
uv pip install -r requirements.txt
uv pip sync requirements.txt
uv pip compile requirements.in -o requirements.txt
uv init my-project
uv add requests
uv add pytest --dev
uv run python main.py
pyenv (Python Version Management)
curl https://pyenv.run | bash
pyenv install --list | grep "3\."
pyenv install 3.12.1
pyenv install 3.11.7
pyenv global 3.12.1
pyenv local 3.11.7
pyenv versions
pyenv uninstall 3.10.0
Pipenv
pip install pipenv
pipenv install
pipenv install requests
pipenv install pytest --dev
pipenv run python main.py
pipenv shell
pipenv lock
pipenv install --deploy
pipenv graph
conda
conda create -n myenv python=3.12
conda create -n myenv python=3.12 numpy pandas
conda activate myenv
conda deactivate
conda install numpy pandas
conda install -c conda-forge package-name
conda env list
conda env export > environment.yml
conda env create -f environment.yml
conda env remove -n myenv
Common Issues
python -m pip install --upgrade pip
pip install --user package-name
pip install --force-reinstall package==1.0
pip cache purge
pip list --outdated
python -c "import package; print(package.__version__)"
Reference
For comparison and migration guides: references/tools.md