0
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)

The code I have above works great from the command prompt. I am wondering why when I try to run the script through Eclipse that I keep getting the "Unresolved import: geopy". I have tried to add it somehow under Project->properties->PYTHONPATH but I am having a bear of time finding out how to get Eclipse to recognize the fact that Geopy is installed to 'C:\Python27\Lib\site-packages\geopy-0.94.2-py2.7.egg'. My version of Eclipse is Juno running on Windows 7 with the JDK7u4 powering it. What should I do about this problem?

Eae
  • 4,191
  • 15
  • 55
  • 92

1 Answers1

0

It appears that under Project->Properties->PyDev - PYTHONPATH there is an area with a tab called "External Libraries". There then is a button to add a zip/jar/egg. The "egg" in question is actually a directory which in my installation is located under:

C:\Python27\Lib\site-packages\geopy-0.94.2-py2.7.egg

So it is added and then Eclipse Juno will allow for the module to be used in the code.

Eae
  • 4,191
  • 15
  • 55
  • 92