Skip to content

Instantly share code, notes, and snippets.

@eaglebh
Forked from ziritrion/pythonenvs.md
Created July 25, 2023 18:03
Show Gist options
  • Save eaglebh/230638e5e72f69c76394c61fa670bccb to your computer and use it in GitHub Desktop.
Save eaglebh/230638e5e72f69c76394c61fa670bccb to your computer and use it in GitHub Desktop.
Cheatsheet for Conda, Pipenv

Conda

  1. Create a virtual environment
    • conda create --name my_env_name python=3.8 or whatever Python version you may need.
  2. List available envs (2 different ways
    • conda env list
    • conda info --envs
  3. Activate virtual env
    • conda activate my_env_name
  4. Deactivate current environment
    • conda deactivate
  5. If pip doesn't work with a fresh conda install:
    • conda install pip
  6. Install project dependencies (listed in requirements.txt file)
    • conda install --file requirements.txt
    • pip install -r requirements.txt
  7. Delete an old environment
    • conda remove --name my_env_name --all
    • conda env remove -n my_env_name
  8. Update conda
    • conda update conda
  9. Update all packages in the current environment
    • conda update --all
  10. Update all packages in another env
    • conda update -n my_env_name --all
  11. List installed packages in current environment
    • conda list
  12. Add conda-forge channel
    • conda config --add channels conda-forge
  13. Check conda channels
    • conda config --show channels
  14. Remove conda-forge channel
    • conda config --remove channels conda-forge
  15. Create an environment file from your current environment.
    • conda env export --from-history > environment.yml
  16. Create a new environment and install dependencies listed in YML file.
    • conda env create -f environment.yml

Pipenv

pipenv does not have built-in package search; make sure you search for the packages at PyPI.

The environments are based on the folder you're on. There is no need to manually name them, and there is no environment activation to take care of per se.

  1. Install a package (this will modify Pipfile and Pipfile.lock)
    • pipenv install some_package
    • pipenv install some_package=1.0
  2. Access the pipenv shell (necessary for enabling the virtualenv and for your script to find the installed packages).
    • pipenv shell
  3. Exit a pipenv shell.
    • deactivate
  4. Install all dependencies to the system, avoiding virtualenvs entirely (useful for deployment in containers)
    • pipenv install --system --deploy

Installing pipenv on Docker Dev Environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment