Skip to main content

Setting Up Your AI/ML Environment

Let's get your development environment ready for AI and machine learning projects! šŸ› ļø

System Requirements​

Minimum Requirements​

  • RAM: 8GB (16GB recommended)
  • Storage: 50GB free space
  • OS: Windows 10+, macOS 10.14+, or Linux Ubuntu 18.04+
  • Internet: Stable connection for downloading packages
  • RAM: 16GB+ for large datasets
  • GPU: NVIDIA GPU with CUDA support (for deep learning)
  • Storage: SSD for faster data loading

Step 1: Install Python​

Why Anaconda?

  • Pre-installed data science packages
  • Environment management
  • Cross-platform compatibility
  • Jupyter Notebook included

Installation Steps:

  1. Download Anaconda

    # Visit: https://www.anaconda.com/products/distribution
    # Download Python 3.9+ version for your OS
  2. Install Anaconda

    • Windows: Run the .exe installer
    • macOS: Run the .pkg installer
    • Linux: Run the .sh script
  3. Verify Installation

    conda --version
    python --version

Option B: Python + pip (For Experienced Users)​

# Install Python 3.9+
# Windows: Download from python.org
# macOS: brew install python
# Linux: sudo apt-get install python3 python3-pip

# Verify installation
python --version
pip --version

Step 2: Create a Virtual Environment​

# Create a new environment
conda create -n ai-ml python=3.9

# Activate the environment
conda activate ai-ml

# Deactivate when done
conda deactivate

Using pip + venv​

# Create virtual environment
python -m venv ai-ml-env

# Activate environment
# Windows:
ai-ml-env\Scripts\activate
# macOS/Linux:
source ai-ml-env/bin/activate

# Deactivate
deactivate

Step 3: Install Essential Libraries​

Core Data Science Stack​

# Activate your environment first
conda activate ai-ml

# Install essential packages
conda install numpy pandas matplotlib seaborn scipy scikit-learn

# Or using pip
pip install numpy pandas matplotlib seaborn scipy scikit-learn

Deep Learning Frameworks​

TensorFlow + Keras​

# CPU version
pip install tensorflow

# GPU version (requires CUDA)
pip install tensorflow-gpu

PyTorch​

# CPU version
conda install pytorch torchvision torchaudio cpuonly -c pytorch

# GPU version (CUDA 11.7)
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

Additional Useful Libraries​

# Jupyter for interactive development
pip install jupyter jupyterlab

# Computer vision
pip install opencv-python pillow

# Natural language processing
pip install nltk spacy transformers

# Web scraping and APIs
pip install requests beautifulsoup4

# Visualization
pip install plotly bokeh

# Model deployment
pip install streamlit flask fastapi

Step 4: Set Up Development Environment​

Option A: Jupyter Notebook/Lab​

# Start Jupyter Notebook
jupyter notebook

# Or Jupyter Lab (recommended)
jupyter lab

Jupyter Features:

  • Interactive code execution
  • Rich output display
  • Markdown documentation
  • Easy sharing

Option B: VS Code​

Install VS Code:

Essential Extensions:

  • Python
  • Jupyter
  • Python Docstring Generator
  • GitLens

VS Code Configuration:

// settings.json
{
"python.defaultInterpreterPath": "~/anaconda3/envs/ai-ml/bin/python",
"jupyter.askForKernelRestart": false,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true
}

Option C: PyCharm​

Features:

  • Intelligent code completion
  • Built-in debugger
  • Scientific tools
  • Professional IDE features

Check GPU Compatibility​

# Check if GPU is available
import tensorflow as tf
print("TensorFlow GPU available:", tf.test.is_gpu_available())

# For PyTorch
import torch
print("PyTorch GPU available:", torch.cuda.is_available())
print("CUDA version:", torch.version.cuda)

Install CUDA (NVIDIA GPUs)​

  1. Check GPU compatibility: https://developer.nvidia.com/cuda-gpus
  2. Download CUDA Toolkit: https://developer.nvidia.com/cuda-downloads
  3. Install cuDNN: https://developer.nvidia.com/cudnn

Step 6: Verify Installation​

Create a test script to verify everything works:

# test_setup.py
import sys
print(f"Python version: {sys.version}")

# Test core libraries
try:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn
print("āœ… Core data science libraries installed successfully!")
except ImportError as e:
print(f"āŒ Missing library: {e}")

# Test deep learning frameworks
try:
import tensorflow as tf
print(f"āœ… TensorFlow {tf.__version__} installed")
print(f"GPU available: {tf.test.is_gpu_available()}")
except ImportError:
print("āŒ TensorFlow not installed")

try:
import torch
print(f"āœ… PyTorch {torch.__version__} installed")
print(f"CUDA available: {torch.cuda.is_available()}")
except ImportError:
print("āŒ PyTorch not installed")

# Test Jupyter
try:
import jupyter
print("āœ… Jupyter installed")
except ImportError:
print("āŒ Jupyter not installed")

print("\nšŸŽ‰ Setup verification complete!")

Run the test:

python test_setup.py

Troubleshooting Common Issues​

Import Errors​

# Update pip
python -m pip install --upgrade pip

# Reinstall problematic package
pip uninstall package_name
pip install package_name

Environment Issues​

# List environments
conda env list

# Remove corrupted environment
conda env remove -n ai-ml

# Recreate environment
conda create -n ai-ml python=3.9

GPU Issues​

  • Ensure CUDA version matches PyTorch/TensorFlow requirements
  • Check GPU drivers are up to date
  • Verify GPU has sufficient memory

Next Steps​

Once your environment is set up, proceed to Python Basics to refresh your Python skills for AI/ML development.

Quick Reference Commands​

# Environment management
conda create -n myenv python=3.9
conda activate myenv
conda deactivate
conda env list

# Package management
conda install package_name
pip install package_name
conda list
pip list

# Jupyter
jupyter notebook
jupyter lab

# Update packages
conda update --all
pip install --upgrade package_name

šŸ’” Pro Tip: Always work in virtual environments to avoid package conflicts and maintain project isolation!