LLM Support Python - Installing Python 3.13 w/ numpy and pandas

Installing Python 3.13 JAG (Just another Guide)

LLM Support Python - Installing Python 3.13 w/ numpy and pandas

Numpy, Pandars are scientific and matrice handling tools very often required in many LLMs (such as Grok). Installing these  can be problematic and can need a particular version of Python to run satisfactory, so:

  • The scripts at the bottom can save you hours from chasing all the little minutia, just paste them in a .sh file, add the chmod +x <file.sh> and then execute it!

To install Python 3.13 on Ubuntu, the recommended approach is to utilize the Deadsnakes PPA, which provides pre-built packages for newer Python versions not yet available in the standard Ubuntu repositories. This method is straightforward and avoids the complexities of compiling from source. As of November 1, 2025, the latest maintenance release in the Python 3.13 series is Python 3.13.9. Follow these steps to proceed:

Prerequisites

Ensure your system is up to date and has the necessary tools for adding repositories:

sudo apt update
sudo apt install software-properties-common

Installation Steps Using Deadsnakes PPA

Add the Deadsnakes PPA repository:

sudo add-apt-repository ppa:deadsnakes/ppa

Update the package index to include the new repository:

sudo apt update

Install Python 3.13:

sudo apt install python3.13

This command installs the core Python interpreter. To include support for virtual environments (venv), also install:

sudo apt install python3.13-venv

Verify the installation:

python3.13 --version

The output should confirm "Python 3.13.9" (or the latest patch version available in the PPA).

Alternative: Building from Source

If you prefer to compile Python 3.13 from source for customization (e.g., enabling optimizations), follow these steps. This requires additional dependencies and may take longer.

Install build dependencies:

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev tk-dev liblzma-dev libmpdec-dev pkg-config

Download the latest Python 3.13 source tarball from the official website:

wget https://www.python.org/ftp/python/3.13.9/Python-3.13.9.tgz
tar -xzf Python-3.13.9.tgz
cd Python-3.13.9

Configure the build with optimizations and pip support:

./configure --enable-optimizations --with-ensurepip=install

Compile and install (using altinstall to avoid overwriting the system Python):

make -j $(nproc)
sudo make altinstall

Verify:

python3.13 --version

Post-Installation Notes

  • The venv module is included by default in Python 3.13. To create a virtual environment, use:
python3.13 -m venv /path/to/myenv
source /path/to/myenv/bin/activate
  • Be cautious with system-wide installations, as they may lead to dependency conflicts with Ubuntu's default Python (typically 3.12 on Ubuntu 24.04). Use virtual environments for project isolation.
  • If you encounter issues, such as unmet dependencies, ensure the PPA is correctly added and consider removing conflicting packages before installation.

If your operating system differs from Ubuntu (e.g., another Linux distribution, Windows, or macOS), please provide additional details for tailored instructions.

A complete installation script as:

#!/bin/bash

# This script installs Python 3.13 on Ubuntu using the Deadsnakes PPA.
# It includes prerequisites, adds the repository, updates packages, and installs Python 3.13 along with venv support.
# Additionally, it creates a local virtual environment (.venv), activates it, updates pip, installs numpy, and deactivates the environment.
# Run this script with sudo privileges if necessary for installation steps.

set -e  # Exit on error

echo "Updating system and installing prerequisites..."
sudo apt update
sudo apt install -y software-properties-common

echo "Adding Deadsnakes PPA repository..."
sudo add-apt-repository ppa:deadsnakes/ppa -y

echo "Updating package index..."
sudo apt update

echo "Installing Python 3.13 and venv module..."
sudo apt install -y python3.13 python3.13-venv

echo "Verifying installation..."
python3.13 --version

echo "Creating local virtual environment (.venv)..."
python3.13 -m venv .venv

echo "Activating virtual environment and updating pip..."
source .venv/bin/activate
pip install --upgrade pip

echo "Installing numpy in the virtual environment..."
pip install numpy pandas grok

echo "Deactivating virtual environment..."
deactivate

echo "Installation complete. You can activate the virtual environment with: source .venv/bin/activate"

If you need an alt-install that is more Debian based, you can try this alt-script

#!/bin/bash

# This script installs Python 3.13 on Parrot OS (Debian-based) by building from source.
# It installs build dependencies (excluding libmpdec-dev, as Python can use a bundled copy), downloads the source, compiles, and installs Python 3.13.
# Additionally, it creates a local virtual environment (.venv), activates it, updates pip, installs numpy, and deactivates the environment.
# Run this script with sudo privileges if necessary for installation steps.
# Note: This assumes Parrot OS (codename 'lory'), where Ubuntu PPAs are not supported, hence building from source.

set -e  # Exit on error

echo "Updating system and installing build dependencies..."
sudo apt update
sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev tk-dev liblzma-dev pkg-config wget

echo "Downloading Python 3.13 source code..."
wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz
tar -xzf Python-3.13.0.tgz
cd Python-3.13.0

echo "Configuring the build with optimizations and pip support..."
./configure --enable-optimizations --with-ensurepip=install

echo "Compiling Python (this may take a while)..."
make -j $(nproc)

echo "Installing Python 3.13 (using altinstall to avoid overwriting system Python)..."
sudo make altinstall

cd ..

echo "Verifying installation..."
python3.13 --version

echo "Creating local virtual environment (.venv)..."
python3.13 -m venv .venv

echo "Activating virtual environment and updating pip..."
source .venv/bin/activate
pip install --upgrade pip

echo "Installing numpy in the virtual environment..."
pip install numpy pandas grok

echo "Deactivating virtual environment..."
deactivate

echo "Installation complete. You can activate the virtual environment with: source .venv/bin/activate"

This script is designed to use all your CPUs..

Linux Rocks Every Day