This repository demonstrates how to create and manage different Python virtual environments for various Python versions using python3-venv
.
When working on projects that require specific Python versions or need isolation from system-wide Python packages, creating virtual environments is a good practice. This repository provides a guide on how to set up virtual environments for different Python versions.
If you prefer to download and compile Python directly from the official Python website, follow these steps:
sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
Replace X.Y.Z with the version number you want to install (e.g., 3.8.12):
wget https://www.python.org/ftp/python/X.Y.Z/Python-X.Y.Z.tgz
tar -xf Python-X.Y.Z.tgz
cd Python-X.Y.Z
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
Check the installed Python version:
python3.8 -V
python3.8 -m venv venv38
Activate the virtual environment:
source venv38/bin/activate
python3.9 -m venv venv39
Activate the virtual environment:
source venv39/bin/activate
pip install virtualenv
Within each activated virtual environment, use pip
to install project-specific dependencies:
pip install package_name
When you're done working in a virtual environment, deactivate it:
deactivate
To delete a virtual environment, run:
rm -rf path/to/venv
Feel free to contribute improvements, additional instructions, or support for other Python versions!