Complete guide for setting up Python and required dependencies for Deep Learning Labs on Windows, Ubuntu, and macOS.
python --version
pip --version
python --version
python --version
conda --version
sudo apt update
sudo apt upgrade -y
sudo apt install python3 python3-pip python3-venv -y
python3 --version
pip3 --version
echo "alias python=python3" >> ~/.bashrc
echo "alias pip=pip3" >> ~/.bashrc
source ~/.bashrc
sudo apt update
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.10 python3.10-venv python3.10-dev -y
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
# Install dependencies
sudo apt install build-essential zlib1g-dev libncurses5-dev \
libgdbm-dev libnss3-dev libssl-dev libreadline-dev \
libffi-dev libsqlite3-dev wget libbz2-dev -y
# Download Python
cd /tmp
wget https://www.python.org/ftp/python/3.10.11/Python-3.10.11.tgz
tar -xf Python-3.10.11.tgz
cd Python-3.10.11
# Configure and install
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall
# Verify
python3.10 --version
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python@3.10
python3 --version
pip3 --version
echo "alias python=python3" >> ~/.zshrc
echo "alias pip=pip3" >> ~/.zshrc
source ~/.zshrc
.pkg installerpython3 --version
python --version
conda --version
# Navigate to project directory
cd path\to\dl-lab
# Create virtual environment
python -m venv venv
# Activate virtual environment
venv\Scripts\activate
# Deactivate when done
deactivate
# Navigate to project directory
cd ~/path/to/dl-lab
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Deactivate when done
deactivate
# Create environment
conda create -n dl-lab python=3.10 -y
# Activate environment
conda activate dl-lab
# Deactivate when done
conda deactivate
# Activate your virtual environment first!
# Install all dependencies
pip install -r requirements.txt
# Verify installation
pip list
# Activate your virtual environment first!
# Install minimal dependencies
pip install -r requirements-minimal.txt
# Verify installation
pip list
# Core dependencies
pip install torch torchvision torchaudio
pip install numpy matplotlib opencv-python pillow
pip install scikit-learn scipy tqdm
# Optional: For specific labs
pip install transformers # For NLP labs
pip install tensorboard # For visualization
nvidia-smi
# For CUDA 11.8
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# For CUDA 12.1
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
import torch
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"CUDA version: {torch.version.cuda}")
print(f"GPU: {torch.cuda.get_device_name(0)}")
# PyTorch with MPS (Metal Performance Shaders) support
pip install torch torchvision torchaudio
# Verify MPS support
python -c "import torch; print(f'MPS available: {torch.backends.mps.is_available()}')"
python --version
pip --version
# Create test script: test_installation.py
import torch
import numpy as np
import cv2
import matplotlib.pyplot as plt
from PIL import Image
print("✓ All packages imported successfully!")
print(f"PyTorch version: {torch.__version__}")
print(f"NumPy version: {np.__version__}")
print(f"OpenCV version: {cv2.__version__}")
Run the test:
python test_installation.py
# Test with Lab 1
cd lab_01_image_processing
python image_processing.py
Solution:
python3 instead of pythonSolution:
# Linux/macOS
python3 -m ensurepip --upgrade
# Windows
python -m ensurepip --upgrade
Solution:
# Don't use sudo with pip in virtual environment
# If outside venv, use --user flag
pip install --user package_name
Solution:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package_name
Solution:
# Use a mirror (example: Tsinghua mirror)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package_name
Solution:
# Create fresh virtual environment
python -m venv fresh_venv
source fresh_venv/bin/activate # or fresh_venv\Scripts\activate on Windows
pip install -r requirements.txt
Solution:
device = 'cpu' in codeSolution:
pip uninstall opencv-python opencv-python-headless
pip install opencv-python
# Check versions
python --version
pip --version
# Create virtual environment
python -m venv venv
# Activate venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# List installed packages
pip list
# Update pip
pip install --upgrade pip
# Deactivate venv
deactivate
After successful installation:
Need Help? Check the Troubleshooting section or create an issue in the repository.