Python Installation for AI/ML Development
This guide covers complete Python installation and configuration for artificial intelligence and machine learning development across all major platforms.
Installing Python on Linux
Ubuntu/Debian Installation
# Update package list
sudo apt update
# Install Python 3 and pip
sudo apt install -y python3 python3-pip python3-dev
# Install Python 3.11 (latest stable)
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.11 python3.11-venv python3.11-dev
# Verify installation
python3 --version
python3.11 --version
pip3 --version
# Install build dependencies
sudo apt install -y build-essential libssl-dev libffi-dev
sudo apt install -y python3-setuptools
# Install additional tools
sudo apt install -y git wget curl
CentOS/RHEL Installation
# Install Python 3
sudo dnf install -y python3 python3-pip python3-devel
# Install development tools
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y openssl-devel bzip2-devel libffi-devel
# Install Python 3.11 from source
cd /tmp
wget https://www.python.org/ftp/python/3.11.7/Python-3.11.7.tgz
tar xzf Python-3.11.7.tgz
cd Python-3.11.7
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall
# Verify
python3.11 --version
pip3.11 --version
Installing Python on Windows
Using Official Installer
# Download Python from python.org
# https://www.python.org/downloads/
# Run installer and check:
# - Add Python to PATH
# - Install pip
# - Install for all users (optional)
# Verify in Command Prompt/PowerShell
python --version
pip --version
# Upgrade pip
python -m pip install --upgrade pip
Using Chocolatey (Windows Package Manager)
# Install Chocolatey first (run as Administrator)
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install Python
choco install python -y
# Refresh environment
refreshenv
# Verify
python --version
Installing Python on macOS
Using Homebrew
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python
brew install python@3.11
# Verify
python3 --version
pip3 --version
# Create symlinks
brew link python@3.11
Virtual Environment Setup
venv (Built-in)
# Create virtual environment
python3 -m venv ml_env
# Activate on Linux/macOS
source ml_env/bin/activate
# Activate on Windows
ml_env\Scripts\activate
# Deactivate
deactivate
# Install packages in virtual environment
pip install numpy pandas scikit-learn
# Save dependencies
pip freeze > requirements.txt
# Install from requirements
pip install -r requirements.txt
Conda Environment
# Install Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
# Create conda environment
conda create -n ml_env python=3.11
# Activate environment
conda activate ml_env
# Deactivate
conda deactivate
# Install packages
conda install numpy pandas scikit-learn
# Export environment
conda env export > environment.yml
# Create from YAML
conda env create -f environment.yml
# List environments
conda env list
# Remove environment
conda env remove -n ml_env
Essential Python Packages for AI/ML
Core Data Science Stack
# Install NumPy (numerical computing)
pip install numpy
# Install Pandas (data manipulation)
pip install pandas
# Install Matplotlib (visualization)
pip install matplotlib
# Install Seaborn (statistical visualization)
pip install seaborn
# Install SciPy (scientific computing)
pip install scipy
# Install Jupyter (interactive notebooks)
pip install jupyter jupyterlab
# Install all at once
pip install numpy pandas matplotlib seaborn scipy jupyter
Machine Learning Libraries
# Install scikit-learn (traditional ML)
pip install scikit-learn
# Install XGBoost (gradient boosting)
pip install xgboost
# Install LightGBM (Microsoft's gradient boosting)
pip install lightgbm
# Install CatBoost (Yandex's gradient boosting)
pip install catboost
# Install all ML libraries
pip install scikit-learn xgboost lightgbm catboost
pip Package Management
Basic pip Commands
# Upgrade pip
pip install --upgrade pip
# Install specific version
pip install numpy==1.24.0
# Install minimum version
pip install "numpy>=1.20.0"
# Install from git repository
pip install git+https://github.com/user/repo.git
# Install in editable mode
pip install -e .
# Install with extras
pip install "package[extra,features]"
# Uninstall package
pip uninstall package_name
# List installed packages
pip list
# Show package info
pip show numpy
# Search packages
pip search keyword
# Check outdated packages
pip list --outdated
# Upgrade all packages
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
Python Configuration
Setting Default Python Version
# Linux - using update-alternatives
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
sudo update-alternatives --config python
# Create alias (add to ~/.bashrc or ~/.zshrc)
alias python=python3.11
alias pip=pip3.11
# Reload shell
source ~/.bashrc
# Windows - Edit PATH environment variable
# Move desired Python version to top of PATH
Python Path Configuration
# View Python paths
python -c "import sys; print('\n'.join(sys.path))"
# Add custom path (temporary)
export PYTHONPATH="${PYTHONPATH}:/path/to/custom/modules"
# Add permanently (add to ~/.bashrc)
echo 'export PYTHONPATH="${PYTHONPATH}:/path/to/modules"' >> ~/.bashrc
source ~/.bashrc
# Windows - Add to Environment Variables
# setx PYTHONPATH "C:\path\to\modules"
Jupyter Notebook Setup
Installation and Configuration
# Install Jupyter
pip install jupyter jupyterlab
# Start Jupyter Notebook
jupyter notebook
# Start JupyterLab
jupyter lab
# Generate config file
jupyter notebook --generate-config
# Set password
jupyter notebook password
# Install kernel for virtual environment
pip install ipykernel
python -m ipykernel install --user --name=ml_env
# List kernels
jupyter kernelspec list
# Remove kernel
jupyter kernelspec uninstall kernel_name
# Install extensions
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
# Enable extensions
jupyter nbextension enable extension_name
Jupyter Server Configuration
# Run on specific port
jupyter notebook --port=8888
# Run on all interfaces
jupyter notebook --ip=0.0.0.0
# Run without browser
jupyter notebook --no-browser
# Full command for remote server
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root
Python Development Tools
Code Formatting and Linting
# Install Black (code formatter)
pip install black
# Format file
black script.py
# Format directory
black .
# Install pylint (linter)
pip install pylint
# Lint file
pylint script.py
# Install flake8
pip install flake8
flake8 script.py
# Install autopep8
pip install autopep8
autopep8 --in-place --aggressive script.py
Testing Tools
# Install pytest
pip install pytest
# Run tests
pytest
# Run with coverage
pip install pytest-cov
pytest --cov=myproject tests/
# Install unittest (built-in)
python -m unittest discover
Troubleshooting Python Installation
Common Issues
# Python not found in PATH
# Linux/macOS - add to ~/.bashrc
export PATH="/usr/local/bin:$PATH"
# pip not found
python -m ensurepip
python -m pip install --upgrade pip
# Permission denied
# Use --user flag
pip install --user package_name
# Or use virtual environment (recommended)
python -m venv env
source env/bin/activate
# SSL certificate errors
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org package_name
# Clear pip cache
pip cache purge
# Reinstall pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Conclusion
This comprehensive guide covers Python installation and setup for AI/ML development. VCCLHOSTING provides GPU servers with Python pre-installed and optimized for machine learning workloads.