Install & Compatibility
Where this runs
tested against v6.1.7 · 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 0.912s · 379.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 14.4s · import 0.870s · 371MB
393MB installed
● package 393MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
units
✓ from astropy import units as u
✗ import astropy.units
The conventional and recommended alias for units is 'u'.
coordinates
✓ from astropy import coordinates as coord
✗ import astropy.coordinates
The conventional and recommended alias for coordinates is 'coord'.
SkyCoord
✓ from astropy.coordinates import SkyCoord
Table
✓ from astropy.table import Table
fits
✓ from astropy.io import fits
✗ from astropy.io.fits import *
Avoid wildcard imports; import the 'fits' sub-package directly or alias it if replacing old 'pyfits'.
constants
✓ from astropy import constants as const
✗ import astropy.constants
The conventional and recommended alias for constants is 'const'.
cosmology (classes/functions)
✓ from astropy.cosmology import FlatLambdaCDM, z_at_value
✗ from astropy.cosmology.flrw import FlatLambdaCDM
As of Astropy 8.0, cosmology classes and functions must be imported directly from `astropy.cosmology`.
This quickstart demonstrates key Astropy functionalities: defining celestial coordinates with `SkyCoord`, performing unit-aware calculations using `Quantity` and `astropy.units`, accessing physical constants via `astropy.constants`, and working with tabular data using `astropy.table`.
import numpy as np
from astropy import units as u
from astropy import constants as const
from astropy.coordinates import SkyCoord
from astropy.table import Table
# Define a SkyCoord object
pos = SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs')
print(f"Sky position: {pos}\n")
# Create a Quantity and perform a calculation
mass = 5.972e24 * u.kg # Earth's mass
radius = 6371 * u.km # Earth's radius
density = mass / (4/3 * np.pi * radius**3)
print(f"Calculated density: {density.to(u.g / u.cm**3):.2f}\n")
# Access a physical constant
c = const.c
print(f"Speed of light: {c.to(u.km/u.s):.0f}\n")
# Create a simple table
data = [
(1, 'NGC 10', 12.5),
(2, 'M 31', 3.4),
(3, 'Abell 2744', 16.0)
]
t = Table(rows=data, names=('id', 'name', 'magnitude'))
print("Example Table:")
print(t)
astropy --version
Debug
Known issues
breakingIn Astropy 8.0, deprecated module-level shim files in `astropy.cosmology` were removed. All cosmology classes and functions must now be imported directly from `astropy.cosmology`.fixUpdate import statements from `from astropy.cosmology.flrw import FlatLambdaCDM` to `from astropy.cosmology import FlatLambdaCDM`.
affects: >=8.0.0
gotchaAnaconda users upgrading Astropy with `pip` can result in a corrupted installation. It is strongly recommended to use `conda` for updates in Anaconda environments.fixAlways update Astropy in Anaconda using `conda update astropy` instead of `pip install astropy --upgrade`.
affects: All versions
gotchaAstropy `Quantity` objects can sometimes lose their units when used with certain NumPy operations or when broadcasted in specific scenarios. Careful attention is needed to ensure unit preservation.fixExplicitly re-apply units or convert to base units before operations where units might be lost. Check `astropy.units` documentation for 'Known Issues' and 'Performance Tips' regarding `Quantity` behavior.
affects: All versions
gotcha`numpy.prod` cannot be directly applied to `Quantity` instances because the resulting unit depends on the input shape, making correct unit handling ambiguous.fixConvert `Quantity` to its value using `.value` before passing to `numpy.prod` if units are not critical for the intermediate step, or perform a manual loop for unit-aware multiplication if necessary.
affects: All versions
deprecatedThe `astropy.test` runner and related API (`astropy.tests.runner.keyword`, `TestRunnerBase`, `TestRunner`) are pending deprecation and will eventually be removed. Downstream packages using `packagename.test` generated with `TestRunner` may also be affected.fixMigrate testing workflows to use `pytest` directly or follow updated guidelines in Astropy's developer documentation for testing.
affects: >=7.2.0 (pending deprecation warning), >=8.0.0 (potential `AstropyDeprecationWarning`)
gotchaWhen defining custom logarithmic units, `u.def_unit` should be avoided as it can lead to unexpected behavior. Logarithmic units should be defined directly.fixDefine logarithmic units directly, e.g., `dBW = u.dB(u.W)` instead of `dBW = u.def_unit('dBW', u.dB(u.W))`. affects: All versions
Errors
Common errors & fixes
ImportError: No module named 'astropy'
Astropy is not installed in the current Python environment.
fixInstall Astropy using pip: `pip install astropy`.
ImportError: No module named astropy.io
The 'astropy.io' module is missing, possibly due to an incomplete installation.
fixEnsure Astropy is correctly installed: `pip install astropy`.
AttributeError: 'module' object has no attribute 'NonLinearLSQFitter'
The 'NonLinearLSQFitter' class was renamed to 'LevMarLSQFitter' in Astropy 0.4 and later.
fixUpdate the import to: `from astropy.modeling.fitting import LevMarLSQFitter`.
AttributeError: module 'astropy.cosmology' has no attribute 'parameters'
The 'parameters' attribute was removed in Astropy 5.1.
fixUpdate the code to use the current API; refer to the Astropy documentation for guidance.
ModuleNotFoundError: No module named 'astropy'
The `astropy` package is not installed in the Python environment being used, or the Python interpreter cannot find it due to incorrect path configurations.
fixEnsure Astropy is installed for your active Python environment using `pip install astropy` or `python -m pip install astropy`. If using Anaconda, `conda install astropy` is recommended.
Upgrade
Version history
8.0.1latest on PyPI · released Jul 5, 2026
Audit
Dependencies
numpyrequiredCore numerical computing dependency, fundamental to Astropy's data structures.
scipyoptionalUsed for various scientific computing tasks, often a dependency for sub-packages.
matplotliboptionalCommonly used for plotting and visualization, especially with Astropy data.
pyarrowoptionalOptional backend for faster ECSV table reading in astropy.io.misc (v7.2+).
pandasoptionalOptional backend for faster ECSV table reading and DataFrame conversion (v7.2+).
narwhalsoptionalUsed for generic DataFrame conversion methods (to_df/from_df) in astropy.table (v7.2+).
certifioptionalImproves SSL certificate verification for remote data downloads on some systems, especially Windows.