Python Environments 101

Arun Kutty
dotStar
Published in
3 min readJun 25, 2019

This post will talk about various options to create environments in python. Before we start any project we create environments which will host different packages or libraries for a particular project .

Photo by Luca Bravo on Unsplash

Ways to create environments and packages in Python

  • pip with virtualenv
  • pipenv as a python package and environment
  • conda
  • poetry
Pipenv

pipenv

Pipenv is used to allow versioned builds for python projects without taking the responsibility of updating versions of sub dependencies. Basic steps in using pipenv are as follows. The corresponding commands are mentioned below as well.

  1. Installing pipenv
  2. Create a New Environment — with a dependency which has no version. This will use the latest version
  3. Create a New Environment with a dependency which has a specific version.
  4. Create a New Environment with a dependency for a particular environment say dev
  5. Get into the environment.
  6. Check for security vulnerabilities
  7. Uninstall a particular dependency / all dependencies

conda — conda uses its own repository rather than pypi which is the official one

Conda is used to install machine learning packages which might be installed in c/ c++ as well . It can also used when we face problems installing machine learning libraries in windows . conda is a general purpose package management system and not a python package management system . Basic steps in using conda are as follows :

  1. Create a folder which should be a default step
  2. Create a new environment
  3. Activating an environment
  4. Install new packages within the environment
  5. Deactivating an environment
  6. Save necessary information to recreate the environment in another machine
  7. Export the environment into an environment file
  8. Create environment from environment file
  9. Delete environment

End to End use case to create a project . Tom is an intern who has been asked to start a program in python. He will have to use package A , Package B for this project .Having learned about conda last week he will follow the conda workflow to create a new project

Poetry

Intuitive CLI to handle python packaging and dependency management

  1. Create a new environment

2. Add new libraries to the project and install them

3.Remove libraries using poetry

With the above 3 options choose which suits you the best based on project requirements . To sum it up . Choose Conda if its a machine learning project . Choose poetry if you want the initial project set up along with cli commands which will handle versioning for you. Choose pipenv if you are already familiar with the tool and are not open for other tools .

--

--