Untangle Python Spaghetti

Deep dive into environments and dependencies management

Do you use virtual enviroments?

Why do we care about virtual enviroments?

Why do we care about virtual enviroments?

  • avoid conflicts
  • preserve versions
  • discard when not needed

Where are your package stored?

How Python finds your packages?

How Python find your packages?

import statement

-> searches for both Python code and extension modules

-> search along `sys.path`

venv

venv

  • comes with CPython
  • the basic environment manager
  • others are based on it: pipenv, poetry

Using venv

Using venv

create a new environment

-> create a folder structures to...

  • store packages and extensions that you installed
  • some scripts for the functionalities

conda

conda

  • comes with Anaconda
  • enviroment manager that...
  • double as pagkage manager
    (conda install)

Using conda

Using conda

  • Similar mechanics but...
  • live by default in the envs/ folder of your Conda directory
  • Independent from venv
  • work on system level
  • works with other languages as well

Using conda

  • conda create --name {env_name}
  • conda create --name {env_name} {python==3.7.5}
  • conda activate {env_name}

 

  • conda env export -f environment.yml
  • conda env create -f environment.yml

Which one?

venv

  • if you are installing from CPython
     
  • if you want to stay in Python ecosystem
     
  • if you are using pip only to install from PyPI

conda

  • if you are using Anaconda
     
  • if you want to manage packages is other languages as well
     
  • if you want your package to come from Anaconda.org

Reference

  • venv: https://docs.python.org/3/library/venv.html
     
  • conda: https://docs.conda.io/projects/conda/en/stable/user-guide/concepts/environments.html

Untangle Python Spaghetti

By Cheuk Ting Ho

Untangle Python Spaghetti

  • 86