Doing it in PyEphem would be awkward because of the maneuvers necessary to reduce its return values to numbers — but it would look something like the following code, which instead uses the more modern Skyfield library for astronomy in Python. (This code also needs SciPy installed, so that its solver can be used to find the exact moment of conjunction:)
import scipy.optimize
from skyfield.api import load, pi, tau
ts = load.timescale()
eph = load('de421.bsp')
sun = eph['sun']
earth = eph['earth']
venus = eph['venus']
# Every month from year 2000 to 2050.
t = ts.utc(2000, range(12 * 50))
# Where in the sky were Venus and the Sun on those dates?
e = earth.at(t)
lat, lon, distance = e.observe(sun).ecliptic_latlon()
sl = lon.radians
lat, lon, distance = e.observe(venus).ecliptic_latlon()
vl = lon.radians
# Where was Venus relative to the Sun? Compute their difference in
# longitude, wrapping the value into the range [-pi, pi) to avoid
# the discontinuity when one or the other object reaches 360 degrees
# and flips back to 0 degrees.
relative_lon = (vl - sl + pi) % tau - pi
# Find where Venus passed from being ahead of the Sun to being behind.
conjunctions = (relative_lon >= 0)[:-1] & (relative_lon < 0)[1:]
# For each month that included a conjunction, ask SciPy exactly when
# the conjunction occurred.
def f(jd):
"Compute how far away in longitude Venus and the Sun are."
t = ts.tt(jd=jd)
e = earth.at(t)
lat, lon, distance = e.observe(sun).ecliptic_latlon()
sl = lon.radians
lat, lon, distance = e.observe(venus).ecliptic_latlon()
vl = lon.radians
relative_lon = (vl - sl + pi) % tau - pi
return relative_lon
for i in conjunctions.nonzero()[0]:
t0 = t[i]
t1 = t[i + 1]
print("Starting search at", t0.utc_jpl())
jd_conjunction = scipy.optimize.brentq(f, t[i].tt, t[i+1].tt)
print("Found conjunction:", ts.tt(jd=jd_conjunction).utc_jpl())
print()
Whichever astronomy library you use, that's the general approach to take: big steps forward through time (in this example, 1 month steps) looking for when Venus passes from being ahead of the Sun to behind it in longitude. Then, return to each of those months and zero in on the exact moment when their longitudes are the same. Here are a few values printed by the above script, which you can spot-check against published values from the USNO or other sources:
Starting search at A.D. 2013-Dec-24 00:00:00.0000 UT
Found conjunction: A.D. 2014-Jan-11 12:24:30.8031 UT
Starting search at A.D. 2015-Jul-28 00:00:00.0000 UT
Found conjunction: A.D. 2015-Aug-15 19:21:55.1672 UT
Starting search at A.D. 2017-Mar-01 00:00:00.0000 UT
Found conjunction: A.D. 2017-Mar-25 10:17:27.5276 UT
Starting search at A.D. 2018-Oct-03 00:00:00.0000 UT
Found conjunction: A.D. 2018-Oct-26 14:16:19.3941 UT
Starting search at A.D. 2020-May-06 00:00:00.0000 UT
Found conjunction: A.D. 2020-Jun-03 17:43:37.7391 UT