Installation geopy python 2.7

Asked

Viewed 107 times

0

I have python 2.7.12 installed on my computer (Ubuntu 16.04) and installed geopy (1.11). However when I try to run my script, this error appears:

from geopy.distance import  lonlat, distance




ImportError: cannot import name lonlat

Can anyone tell me what pq? And how I do p/ fix?

  • How installed? Are you sure you installed correctly, no errors?

  • 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.

  • Try to download and install manually. if you give a from geopy.distance import lonlat in the console returns the same error?

  • 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

  • In doing python --version same version 2.7 appears?

  • Yes! Python 2.7.12 appears

  • 1

    You could use from geopy import distance and then use the function lonlat calling with distance.lonlat(). If you can put the full code in the question

  • 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 with sudo also.

  • As I added in the answer, the problem is in the geopy version. You need to install the latest version to use lonlat

Show 4 more comments

1 answer

1


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().

  • 1

    But I don’t see why that would interfere. If geopy.distance possesses lonlat, then should work the from .. import in the same way: https://repl.it/@acwoss/Livelyorderlylivecd, so much so that the very documentation you quoted does so.

  • Her code is functional (Repl.it) the problem is with package installation.

  • Thus doing: point = Istance.lonlat(41.49008, -71.312796), also wrong... The error that appears eh: Attributeerror: type Object 'vincenty' has no attribute 'lonlat'. I also think the problem should be in the installation, I just don’t know how to do p/ tidy...as I said before, I’m new in linux

  • The answer does not say that the other way to use the import is wrong. I put the "try" because I tested with version 1.16.0 (last) and after it worked I realized that her problem is because she is using version 1.11.0. I’ll edit the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.