Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 4.184s · 318.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 12.2s · import 3.934s · 315MB
327MB installed
● package 327MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Spectrum1D
✓ from specutils import Spectrum1D
✗ from specutils import Spectrum1D as Spectrum1D
No common mistake; classic import is correct.
SpectralRegion
✓ from specutils import SpectralRegion
✗ import SpectralRegion
SpectralRegion is a class in specutils, not a top-level module.
Basic usage: create a Spectrum1D and extract a spectral region.
import numpy as np
from specutils import Spectrum1D, SpectralRegion
from specutils.manipulation import extract_region
from astropy import units as u
# Create a simple spectrum
flux = np.array([1.0, 2.0, 3.0]) * u.Jy
spectral_axis = np.array([5000, 5010, 5020]) * u.Angstrom
spec = Spectrum1D(spectral_axis=spectral_axis, flux=flux)
# Extract a region
region = SpectralRegion(5005 * u.Angstrom, 5015 * u.Angstrom)
extracted = extract_region(spec, region)
print(extracted)
Debug
Known issues
breakingIn specutils 2.x, the class previously known as Spectrum1D is now Spectrum and Spectrum1D is an alias. Code relying on Spectrum1D subclassing may break if using isinstance checks against old class hierarchy.fixUse 'from specutils import Spectrum' for new code, or continue using Spectrum1D as an alias.
affects: 2.0.0 and later
breakingSupport for Python 3.10 dropped in specutils 2.2.0. Python 3.11 or later is required.fixUpgrade to Python >=3.11.
affects: 2.2.0 and later
deprecatedThe 'spectral_axis_index' keyword argument introduced in 2.0 is deprecated in favor of automatic detection. Using it may emit deprecation warnings.fixRemove spectral_axis_index and rely on automatic axis ordering.
affects: 2.0.0 through current
gotchaWhen passing a SpectralRegion to extract_region, if the units of the region do not match the spectrum's spectral axis units, an error may not be raised immediately but results can be incorrect. Always ensure consistent units.fixUse equivalencies if needed, e.g., via astropy.units.equivalencies.spectral().
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'specutils' has no attribute 'Spectrum1D'
Outdated specutils version (<1.20) where Spectrum1D was not yet exposed at top level.
fixUpgrade specutils to >=1.20: pip install --upgrade specutils
ValueError: The spectral axis must be monotonically increasing.
Spectral axis values are not sorted in ascending order.
fixEnsure spectral_axis is sorted: spec = Spectrum1D(spectral_axis=np.sort(spectral_axis), flux=flux)
ImportError: No module named 'gwcs'
Missing optional dependency for GWCS support.
fixInstall gwcs: pip install gwcs
Upgrade
Version history
2.4.0latest on PyPI · released Jun 1, 2026
Audit
Dependencies
astropyrequiredCore dependency for units, quantities, and WCS
gwcsoptionalFor generalized WCS support in Spectrum2D
scipyrequiredFor interpolation and fitting backends
ndcubeoptionalFor multi-dimensional spectral cubes