Oldest Supported NumPy
Oldest-supported-numpy is a meta-package that dynamically provides the oldest compatible NumPy version for a given Python interpreter and platform. It ensures that if a platform only gained support for NumPy wheels at a more recent version, that specific version is provided. The current version is 2023.12.21, and its release cadence is irregular, typically updated when new NumPy versions or platform support changes warrant it.
Warnings
- gotcha The `oldest-supported-numpy` package itself does not have a Python API to import. Its sole purpose is to act as a dependency resolver, ensuring that a compatible (and often oldest-supported) version of the actual `numpy` package is installed into your environment.
- gotcha The *specific* NumPy version installed by `oldest-supported-numpy` is dynamic. It depends on your Python interpreter version (`sys.version_info`) and the platform/architecture you are running on (e.g., Linux, macOS, Windows, ARM, x86-64). It prioritizes the oldest *available wheel* for your specific environment, not necessarily the absolute oldest NumPy release.
- gotcha Using `oldest-supported-numpy` can lead to non-deterministic NumPy versions across different environments if those environments use varying Python versions. For example, Python 3.8 might get NumPy 1.20, while Python 3.9 might get NumPy 1.22.
Install
-
pip install oldest-supported-numpy
Quickstart
import subprocess
import sys
# Install oldest-supported-numpy, which in turn installs a specific numpy version
# This example assumes pip is installed and available
# In a real environment, you'd typically do 'pip install oldest-supported-numpy' once.
# For this quickstart, we ensure numpy is uninstalled first to demonstrate the effect.
try:
# Uninstall numpy if present to ensure oldest-supported-numpy picks it up
subprocess.run([sys.executable, '-m', 'pip', 'uninstall', '-y', 'numpy'], check=True, capture_output=True)
except subprocess.CalledProcessError as e:
# This is expected if numpy isn't installed initially
pass # print(f"Uninstall failed (expected if not present): {e.stderr.decode().strip()}")
# Install oldest-supported-numpy, which will pull in a specific numpy version
subprocess.run([sys.executable, '-m', 'pip', 'install', 'oldest-supported-numpy'], check=True, capture_output=True)
# Now, import numpy and check its version
import numpy as np
print(f"NumPy version installed by oldest-supported-numpy: {np.__version__}")
# Basic NumPy usage
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = a + b
print(f"Example NumPy array operation: {c}")