Skip to content

Latest commit

 

History

History
202 lines (135 loc) · 2.61 KB

File metadata and controls

202 lines (135 loc) · 2.61 KB

Python Environments Cheatsheet

There are a lot of choices these days for python virtual environments. This cheatsheet covers the basics of all of them so I can easily switch between when working with different teams. No favorites here!

  • pipenv
  • poetry
  • venv
  • conda
  • virtualenv

Pipenv

Reference: Pipenv

Pipenv uses pip for dependency management and virtualenv for creating virtual environments.

Install:

pip install --user pipenv

Create env or activate:

pipenv shell

Deactivate:

exit

Add dependencies:

# normal install
pipenv install langchain

# install specific version
pipenv install langchain==0.2.1

# install as dev dependency
pipenv install pytest --dev

# install all dependencies
pipenv install

# install all plus dev dependencies
pipenv install --dev

Remove dependencies:

# remove dependency
pipenv uninstall langchain

# remove all dev dependencies
pipenv uninstall --all-dev

# remove all dependencies
pipenv uninstall --all

Update dependencies:

# update all dependencies
pipenv update

# update specific dependency
pipenv update langchain

Create lockfile (Pipfile.lock):

pipenv lock

Use with requirements.txt:

pipenv lock --requirements > requirements.txt
pipenv install --requirements requirements.txt

Locate the virtual environment:

pipenv --venv

Delete the virtual environment:

pipenv --rm

Poetry

Reference: Poetry

Install:

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

Create env or activate:

poetry shell

Usage:

# add dependency
poetry add langchain

# install specific dependency
poetry install langchain==0.2.1

# add dev dependency
poetry add pytest --dev

# install all dependencies
poetry install

# install all plus dev dependencies
poetry install --dev

Locate the virtual environment:

poetry env info

Delete the virtual environment:

poetry env remove

venv

Reference: venv

Create env or activate:

python -m venv myenv
source myenv/bin/activate

Usage:

pip install langchain
...

conda

Reference: conda

Create env or activate:

conda create -n myenv

Usage:

conda install langchain

virtualenv

Reference: virtualenv

Create env or activate:

python -m venv myenv
source myenv/bin/activate

Usage:

pip install langchain
...