Virtual Environment
tip
Always create a virtaul environment .venv inside of the project folder. And, don't add any source code inside the .venv folder.
Create an virtual environment
Create a project folder
mkdir my-project
cd my-project
Create virtual environment inside a project folder
Python virtualenv is built into Python, other tools are Conda, pipenv, Poetry for creating virtual environments.
# Here .venv is the name of the virtual environment
python -m venv .venv
Activate an environment
Activate virtual environment
.venv\Scripts\activate.bat
.venv\Scripts\activate.ps1
De-activate virtual environment
deactivate
Install Individual Packages
PIP command => Preferred Installer Program
# To see installed packages
pip list
# To install packges
pip install requests
Save packges to a file
To save list of packages installed in the project
pip freeze > requirements.txt
Install packages from a file
To install packages from the file
pip install -r requirements.txt