Creating Python Virtual Environment and Managing Dependency

What is virtual environment?

At its core, the main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has.

Tools with functionality to create and manage virtual environments:

  • venv (part of the standard library)
  • virtualenv (widely-used)
  • pipenv (high-level interface)
  • conda (not only for python)

What is dependecy management?

Dependency management is the keystone of a sustainable, secure project for Python. If your dependencies are well managed, you won’t find yourself on the wrong end of a long-term support timeline or have dependencies that are out of step with one another. It is a concept that is difficult to grasp in the beginning but indispensable afterwards.

What is the relationship between Virtual Environments and Package Management Tools?

  • venv and virtualenv use pip as a package management tool.
  • conda and pipenv are both package management and virtual environment.

Conda Usage

Conda: package and venv management tool (anaconda repository)

  • install package: conda install package_name
  • install packages: conda install package_name1, package_name2
  • install package with spesific version: conda install package_name=version
  • remove package: conda remove package_name
  • listing installed packages: conda list
  • upgrade package: conda upgrade conda
  • upgrade all packages: conda upgrade -all
  • update current package: conda update package_name
  • update all current package: conda update -all
  • search package: conda search *search_term*
  • creating new environment: conda create -n environment_name
  • activating an environment: conda activate environment_name
  • creating environment with specific version of python: conda create -n environment_name python=version
  • creating environment with packages: conda create -n env_name list of packages
  • deactivate an environment: conda deactivate
  • listing environments: conda env list
  • removing package: conda remove package_name
  • removing environments: conda env remove -n env_name
  • saving the packages to a YAML file: conda env export > environment.yaml

--

--

--

Data Science Enthusiast — For more information check out my LinkedIn page here: www.linkedin.com/in/berkayihsandeniz

Love podcasts or audiobooks? Learn on the go with our new app.

[Case Study] From Markdown and WordPress to LwDITA, GitHub, and Zendesk

A Tale of Two Brothers: The Road to Leadership

The top data structures you should know for your next coding interview

A Git Workflow for Teams

7 Steps to K8s: How We Moved Our Entire Platform

Climb up animation in Unity

Throttling in Web application: with code — Django app

3 reasons hosting my website on AWS S3 didn’t work

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Berkay

Berkay

Data Science Enthusiast — For more information check out my LinkedIn page here: www.linkedin.com/in/berkayihsandeniz

More from Medium

How to create a secure OTP service with twilio verify and python

Web Scraping ebay with selenium and export data to csv

Data Pipeline using Python

Using Python to perform ETL to analyze factors affecting the purchasing behavior of shampoo product…