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 ephemVerified import paths — ran on the pinned version, not inferred.
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.
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).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.
Always remember to call `body.compute(observer)` after modifying `observer.date` or if you're working with a new `Observer` instance.
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.
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`.
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`.
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)`.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.
No dependency data recorded yet.