Registry / data / ephem
library4.2.1pypypi✓ verified 29d ago

PyEphem is a Python library for computing positions of the planets and stars. It provides precise astronomical calculations, including positions of celestial bodies, times of sunrise/sunset, moon phases, and more, based on standard algorithms. The current version is 4.2.1, with releases typically occurring a few times a year for minor updates and bug fixes, and major versions every 1-2 years.

pip install ephem
INSTALL
IMPORT
SIG · EPHEM
E
ephem
datapythonv4.2.1
Install
1.6s avg
Import
10ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.2.1 · 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
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 21.1MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.008s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ephem
✓ import ephem
Observer
✓ import ephem observer = ephem.Observer()
✗ from ephem import Observer # While technically correct, 'import ephem' is more common for accessing other body objects.
Most users 'import ephem' and then access objects like 'ephem.Observer', 'ephem.Mars', etc.

This quickstart demonstrates how to create an observer, set its location and time (important: use UTC!), create a celestial body, compute its position relative to the observer, and print its coordinates, explicitly converting radian outputs to degrees for human readability.

import ephem import datetime # Create an observer at a specific location and time (UTC) boston = ephem.Observer() boston.lat = '42.35' # North latitude boston.lon = '-71.05' # West longitude boston.elevation = 0 # Meters above sea level boston.date = datetime.datetime.utcnow() # Set date to current UTC time # Create a planet object (Mars) mars = ephem.Mars() # Compute its position for the observer's location and time mars.compute(boston) # Print celestial coordinates, converting radians to degrees for readability print(f"Mars Right Ascension (RA): {ephem.degrees(mars.ra)}") print(f"Mars Declination (Dec): {ephem.degrees(mars.dec)}") print(f"Mars Azimuth: {ephem.degrees(mars.az)}") print(f"Mars Altitude: {ephem.degrees(mars.alt)}") print(f"Mars Distance: {mars.range:.2f} AU")
Debug
Known issues
gotchaPyEphem uses radians for all internal angle calculations and returns values in radians by default. For human-readable output or input, explicitly convert using `ephem.degrees()`.
fix
Always use `ephem.degrees(value)` when printing angles to convert radians to degrees, or when setting angles if your input is in degrees (e.g., `observer.lat = ephem.degrees('42.35')` if '42.35' was in degrees but ephem expected radians, though in lat/lon strings are parsed correctly).
affects: All versions
gotchaPyEphem operates internally on UTC (Coordinated Universal Time). Providing naive `datetime` objects that are meant to be local time will be misinterpreted as UTC, leading to incorrect calculations.
fix
Always provide UTC `datetime` objects to `observer.date` (e.g., `datetime.datetime.utcnow()`, or a timezone-aware `datetime` object converted to UTC). Alternatively, use `ephem.localtime()` to convert a UTC date to local time before setting, if you specifically need local time input.
affects: All versions
gotchaAfter changing an observer's date or creating a new observer, you MUST call the `.compute(observer)` method on celestial body objects to update their positions for the new time/location. Failing to do so will result in calculations based on the body's default epoch or previous observer's time.
fix
Always remember to call `body.compute(observer)` after modifying `observer.date` or if you're working with a new `Observer` instance.
affects: All versions
gotchaLatitude and longitude strings can be provided directly to `observer.lat` and `observer.lon` (e.g., `'42.35'`), but ensure you understand the sign conventions: positive for North/East, negative for South/West. If providing floats, they are assumed to be in radians unless explicitly converted.
fix
Use string inputs like `'42.35'` for lat/lon for clarity, which PyEphem parses correctly. If using floats, ensure they are in radians or apply `ephem.degrees()` for conversion if you are using degree values.
affects: All versions
Errors
Common errors & fixes
ImportError: No module named 'ephem'
The `ephem` library is either not installed in the active Python environment or there's a conflict with multiple Python installations or virtual environments.
fix
Ensure `ephem` is installed for your current Python interpreter: `pip install ephem` or `python -m pip install ephem`. If using Anaconda, try `conda install ephem`.
AttributeError: 'Sun' object has no attribute 'ha'
You are trying to access an attribute (like 'ha' or 'mag') that either doesn't exist for that specific celestial body object, or it has not been computed yet by calling the `compute()` method on the object with an observer or date.
fix
First, call the `compute()` method on the celestial body object (e.g., `sun.compute(observer)`) before trying to access its attributes. If the attribute still doesn't exist, consult the `ephem` documentation for available attributes for that body type. For example, `ephem.Moon` and `ephem.PlanetMoon` objects typically lack a `.mag` attribute, which is only available for `ephem.Body` objects like `ephem.Sun`.
TypeError: 'float' object is not callable
This error often occurs when attempting to call `ephem.degree()` as a function. The correct function to convert degrees to radians (or to create an angle object from a string representing degrees) is `ephem.degrees()` (plural). `ephem.degree` (singular) is a float constant representing one degree in radians.
fix
Use `ephem.degrees()` (plural) when you intend to call a function for angle conversion or parsing. For example: `angle_in_radians = ephem.degrees('90')` or `angle_in_radians = ephem.degrees(90)`.
ephem giving incorrect sunrise/sunset or celestial positions
PyEphem primarily works with Universal Time (UTC) and expects dates to be in UTC. Incorrect results often stem from not converting local times to UTC before passing them to `ephem.Date` or `Observer.date`, or by not correctly setting the observer's longitude, latitude, and elevation, or missing the `compute()` call.
fix
Always ensure dates and times provided to `ephem` are in UTC. If using `datetime` objects, convert them to UTC first. Also, ensure the `Observer` object's `lon`, `lat`, and `elevation` are set correctly, and that `observer.pressure` and `observer.temperature` are set for accurate atmospheric refraction if needed. Crucially, always call `body.compute(observer)` or `body.compute(date)` to calculate the position for the specified observer/date.
Upgrade
Version history
4.2.1latest on PyPI · released Feb 28, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
28
Amazon
3
OpenAI (training)
1
Resources
ephem — pip install ephem · libregistry