{"id":2494,"library":"ephem","title":"PyEphem","description":"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.","status":"active","version":"4.2.1","language":"python","source_language":"en","source_url":"https://github.com/brandon-rhodes/pyephem","tags":["astronomy","celestial mechanics","astrophysics","calculations","time"],"install":[{"cmd":"pip install ephem","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"ephem","correct":"import ephem"},{"note":"Most users 'import ephem' and then access objects like 'ephem.Observer', 'ephem.Mars', etc.","wrong":"from ephem import Observer # While technically correct, 'import ephem' is more common for accessing other body objects.","symbol":"Observer","correct":"import ephem\nobserver = ephem.Observer()"}],"quickstart":{"code":"import ephem\nimport datetime\n\n# Create an observer at a specific location and time (UTC)\nboston = ephem.Observer()\nboston.lat = '42.35'  # North latitude\nboston.lon = '-71.05' # West longitude\nboston.elevation = 0  # Meters above sea level\nboston.date = datetime.datetime.utcnow() # Set date to current UTC time\n\n# Create a planet object (Mars)\nmars = ephem.Mars()\n\n# Compute its position for the observer's location and time\nmars.compute(boston)\n\n# Print celestial coordinates, converting radians to degrees for readability\nprint(f\"Mars Right Ascension (RA): {ephem.degrees(mars.ra)}\")\nprint(f\"Mars Declination (Dec): {ephem.degrees(mars.dec)}\")\nprint(f\"Mars Azimuth: {ephem.degrees(mars.az)}\")\nprint(f\"Mars Altitude: {ephem.degrees(mars.alt)}\")\nprint(f\"Mars Distance: {mars.range:.2f} AU\")","lang":"python","description":"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."},"warnings":[{"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).","message":"PyEphem 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()`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"PyEphem 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always remember to call `body.compute(observer)` after modifying `observer.date` or if you're working with a new `Observer` instance.","message":"After 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Latitude 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'-2':61 '1':60 '4.2.1':40 'algorithm':35 'astronom':18 'astronomi':63 'astrophys':66 'base':32 'bodi':24 'bug':54 'calcul':19,67 'celesti':23,64 'comput':8 'current':37 'everi':59 'fix':55 'includ':20 'librari':6 'major':57 'mechan':65 'minor':51 'moon':28 'occur':44 'phase':29 'planet':12 'posit':9,21 'precis':17 'provid':16 'pyephem':1,2 'python':5 'releas':42 'standard':34 'star':14 'sunrise/sunset':27 'time':25,47,68 'typic':43 'updat':52 'version':38,58 'year':49,62","created_at":"2026-04-11T01:30:29.948969+00:00","updated_at":"2026-04-16T14:50:08.999868+00:00","problems":[{"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`.","cause":"The `ephem` library is either not installed in the active Python environment or there's a conflict with multiple Python installations or virtual environments.","error":"ImportError: No module named 'ephem'"},{"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`.","cause":"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.","error":"AttributeError: 'Sun' object has no attribute 'ha'"},{"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)`.","cause":"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.","error":"TypeError: 'float' object is not callable"},{"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.","cause":"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.","error":"ephem giving incorrect sunrise/sunset or celestial positions"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.2.1","cli_name":"","cli_version":null,"type":"library","homepage":"http://rhodesmill.org/pyephem/","github":"https://github.com/brandon-rhodes/pyephem","docs":null,"changelog":null,"pypi":"https://pypi.org/project/ephem/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}