import csv
from geopy import geocoders
import time
g = geocoders.Google()
spamReader = csv.reader(open('locations.csv', 'rb'), delimiter='\t', quotechar='|')
f = open("output.txt",'w')
for row in spamReader:
a = ', '.join(row)
#exactly_one = False
time.sleep(1)
try:
place, (lat, lng) = g.geocode(a)
except (ValueError, geocoders.google.GQueryError, geocoders.google.GeocoderResultError, geocoders.google.GBadKeyError, geocoders.google.GTooManyQueriesError):
#print("Error: geocode failed on input %s with message %s"%(a, error_message)
f.write("exception")
continue
b = str(place) + "," + "[" + str(lat) + "," + str(lng) + "]" + "\n"
print b
f.write(b)
我上面的代码在命令提示符下效果很好。我想知道为什么当我尝试通过 Eclipse 运行脚本时,我不断收到“未解决的导入:geopy”。我试图以某种方式在 Project->properties->PYTHONPATH 下添加它,但我有时间找出如何让 Eclipse 识别 Geopy 安装到'C:\Python27\Lib\site-packages\ geopy-0.94.2-py2.7.egg'。我的 Eclipse 版本是在 Windows 7 上运行的 Juno,由 JDK7u4 驱动。这个问题我该怎么办?