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: 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