Welcome to the

Home Page!

Table of Contents
Quick Reference

Download PyEphem for Windows, Linux, or as source code, directly from the Python Package Index.

PyPI PyEphem page
Includes Windows installers!

The project source code and issue tracker are hosted on GitHub.

Code Repository
Issue Tracker

PyEphem Home Page

Welcome to the home page of the PyEphem astronomy library for Python!

>>> import ephem
>>> mars = ephem.Mars()
>>> mars.compute('2007/10/02 00:50:22')
>>> print mars.ra, mars.dec
6:05:56.34 23:23:40.0
>>> ephem.constellation(mars)
('Gem', 'Gemini')

Since its first release in 1998, PyEphem has given Python programmers the ability to compute planet, comet, asteroid, and Earth satellite positions. It wraps the “libastro” C library that powers the XEphem astronomy application for UNIX — whose author Elwood Downey generously gave permission for PyEphem to use his library with Python. PyEphem can also compute the angular separation between two objects in the sky, determine the constellation in which an object lies, and find the times an object rises, transits, and sets.

PyEphem will continue to receive critical bugfixes and be ported to each new version of Python. But be warned that it has some rough edges!

  • The Skyfield astronomy library should be preferred over PyEphem for new projects. Its modern design encourages better Python code, and uses NumPy to accelerate its calculations.
  • Because PyEphem includes a C library, installation issues often frustrate users. If the Package Index lacks a wheel for your system, you will need a C compiler and Python development environment to get PyEphem installed.
  • Instead of making angular units explicit in your code, PyEphem tried to be clever but only wound up being obscure. An input string '1.23' is parsed as degrees of declination (or hours, when setting right ascension) but a float 1.23 is assumed to be in radians. Angles returned by PyEphem are even more confusing: print them, and they display degrees; but do math with them, and you will find they are radians. This causes substantial confusion and makes code much more difficult to read, but can never be fixed without breaking programs that already use PyEphem.
  • The PyEphem compute() method mutates its object in-place instead of returning results. While this reflects how the underlying C library works, it makes it hard to use compute() inside a list comprehension — you get a list of None objects.
  • PyEphem generates positions using the 1980s techniques popularized in Jean Meeus’s Astronomical Algorithms, like the IAU 1980 model of Earth nutation and VSOP87 planetary theory. These make PyEphem faster and more compact than modern astronomy libraries, but limit its accuracy to around 1 arcsecond. This is often sufficient for most amateur astronomy, but users needing higher precision should investigate a more modern Python astronomy library like Skyfield or AstroPy.

Here’s more example code to illustrate how PyEphem works:

>>> boston = ephem.Observer()
>>> boston.lat = '42.37'
>>> boston.lon = '-71.03'
>>> boston.date = '2007/10/02 00:50:22'
>>> mars.compute(boston)
>>> print mars.az, mars.alt
37:55:48.9 -14:23:11.8
>>> print(boston.next_rising(mars))
2007/10/2 02:31:51
>>> print mars.az         # degrees when printed
>>> print mars.az + 0.0   # radians in math
>>> print(boston.next_transit(mars))
2007/10/2 10:07:47
>>> print mars.alt        # degrees when printed
>>> print mars.alt + 0.0  # radians in math

Installing PyEphem

You can try installing PyEphem with:

$ pip install pyephem

Better yet, you can use virtualenv to create a virtual environment, and then run its pip instead of your system-wide one. Then you will avoid having to gain administrator rights on your machine before performing the installation.

If instead you want to download the Windows installer or even the raw PyEphem source code, you should visit the PyEphem entry at the Python Package Index, or use the links at the top of this page.