&& cd $_ # create proj1 and cd into proj1
mkdir proj -m venv venv1 # run python module venv and create venv1
python # note: venv1 folder is created (inside proj1)
ls /bin/activate # activate venv1 by running bash script with source
source venv1# note: (venv1) appears in front of (base) in terminal
(venv1) # note: no packages installed so no output
pip freeze # install packages required
pip install sqalchemy # see list of packages installed
pip freeze # deactivate venv1 deactivate
1. Virtual Environments
A virtual environment in Python is a self-contained directory that contains a Python installation and a set of packages.
This post will go through 3 methods to create virtual environments: - venv
- conda
virtual environments - pipenv
2. Purpose
Dependency Management:
- Different projects may require different versions of the same package.
- Virtual environments allow you to maintain these dependencies separately.
Isolation:
- Packages installed in a virtual environment are isolated from those installed system-wide or in other virtual environments
- Reducing the risk of version conflicts and compatibility issues.
Portability:
- A virtual environment can be easily replicated on another system by sharing the environment configuration file, such as requirements.txt.