Try to use the distance
as follows:
Existing example in documentation of geopy
from geopy import distance
newport_ri = (41.49008, -71.312796)
cleveland_oh = (41.499498, -81.695391)
print(distance.distance(newport_ri, cleveland_oh).miles)
For lonlat can do the same:
from geopy import distance
point = distance.lonlat(41.49008, -71.312796)
print(point)
Edited after marked as accepted.
After checking the comments and continuing pointing the error was verified that the function distance.lonlat
did not exist in version 1.11.0 of the package geopy
. Was added in the version 1.14.0 and can be seen by the release comment:
1.14.0
ADDED: geopy.distance.lonlat Function for conveniently Converting (x,
y, [z]) coordinate tuples to the Point instances, which use (y, x,
[z]).
For this reason the import error occurs. The comments also indicated that the import used in the question is not wrong and can be used since the right version of geopy
be installed.
The code that uses the distance
works in version 1.11.0 with import done as it is in that answer and not as it is in the question because the distance
exists in version 1.11.0, but it points to the Vincenty method. In the latest version the distance
started pointing to the Geodesic method and included the function lonlat()
.
How installed? Are you sure you installed correctly, no errors?
– Woss
Apparently yes, I used: sudo Pip install geopy. This message appeared: Requirement already satisfied: geopy in /usr/local/lib/python2.7/dist-Packages (1.11.0) Bleach 2.1.3 has requirement tml5lib!= 1.0b1,!= 1.0b2,!= 1.0b3,!= 1.0b4,!= 1.0b5,!= 1.0b6,!= 1.0b7,!= 1.0b8,>=0.99999999pre, but you’ll have html5lib 0.9999999 which is incompatible. But I checked p/ see if it was installed, and this.
– Luana
Try to download and install manually. if you give a
from geopy.distance import lonlat
in the console returns the same error?– Tuxpilgrim
How so install manually? Sorry, besides python I am new to linux too... And to answer your question, yes...by doing this on the console, the error is the same
– Luana
In doing
python --version
same version 2.7 appears?– Woss
Yes! Python 2.7.12 appears
– Luana
You could use
from geopy import distance
and then use the functionlonlat
calling withdistance.lonlat()
. If you can put the full code in the question– Pagotti
I just tested and the code is OK. You have to find out what environment the package was installed in. How it was installed with
sudo
it is likely that the package will not be visible if the script does not run withsudo
also.– fernandosavio
As I added in the answer, the problem is in the geopy version. You need to install the latest version to use lonlat
– Pagotti