How to Install Python and Set Up a Virtual Environment
Python is a versatile language for automation, web apps and data. Ubuntu ships with Python 3; here’s how to set up an isolated project environment.
1. Verify Python and install tooling
python3 --version
sudo apt update
sudo apt install -y python3-pip python3-venv2. Create a virtual environment
mkdir myproject && cd myproject
python3 -m venv venv
source venv/bin/activateYour prompt now shows (venv). Packages you install stay isolated to this project.
3. Install packages
pip install requests flask
pip freeze > requirements.txt4. Deactivate when done
deactivateRecreate the environment elsewhere with pip install -r requirements.txt.