1

I am trying to install Geopy in Python. How do I do this in really simple terms? I have Python 3.4.0 launcher installed. Where do I write the Geopy install command? On a text file with a .py extension? Or in Terminal? I have read to ways to install Geopy, using easy-install and pip. Which one should I use? Below is one example I have read:

mkdir -p $HOME/lib/pythonX.Y, where X.Y is the Python version, and press Enter.
easy_install-X.Y package, where package is the name of the package to install, and press Enter.

Below is another installation I have read:

pip install geopy

>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.geocode("175 5th Avenue NYC")
>>> print(location.address)
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
>>> print(location.latitude, location.longitude)
(40.7410861, -73.9896297241625)
>>> print(location.raw)
{u'place_id': u'9167009604', u'type': u'attraction', ...}

So, in the above code, where am I writing this, because this is printing the result upon request? In Terminal? I have the Python launcher but I can't seem to write a new script within it, it just loads text files with the .py extension.

Apologies for the asking about the basics here. Very much a novice. If anyone could explain how I could install Geopy and execute the above geocoding technique in a step-by-step way, it would be very much appreciated.

user2020088
  • 51
  • 1
  • 4
  • 11

3 Answers3

9

Assuming you have pip installed (as miles mentioned), in terminal, type:

pip install geopy

Then you should be able to use the geopy module in python. Try from terminal

python
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
...etc
Kieran Bristow
  • 348
  • 2
  • 11
  • Thanks for the help from yourself and @miles82. The above advice has returned this: Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin; pip install geopy; File "", line 1 pip install geopy ^ SyntaxError: invalid syntax; -m pip install geopy; File "", line 1 -m pip install geopy ^ SyntaxError: invalid syntax; -m ensurepip; File "", line 1 -m ensurepip ^ SyntaxError: invalid syntax; pip install geopy; File "", line 1 pip install geopy SyntaxError: invalid syntax – user2020088 Oct 09 '14 at 12:12
  • Enter the commands in terminal, looks like you are trying to enter them in the python interpreter? – Kieran Bristow Oct 09 '14 at 12:17
  • This was in Terminal. First, I typed 'python', which loaded the first line pasted above. – user2020088 Oct 09 '14 at 12:56
  • It says Python 2.7.5 above. But when I launch the Python Launcher it's 3.4.0. So maybe pip isn't pre-installed in 2.7.5? – user2020088 Oct 09 '14 at 12:57
  • If i go ahead and just type 'pip install geopy' as soon as the Terminal opens (without first typing 'python') then it returns: Macintosh:~ user$ pip install geopy -bash: pip: command not found – user2020088 Oct 09 '14 at 13:00
  • To clarify, when I am saying terminal, I mean before typing 'python'. pip is not pre-installed with 2.7. See the following to install pip on mac http://stackoverflow.com/questions/17271319/installing-pip-on-mac-os-x . Then attempt again. – Kieran Bristow Oct 09 '14 at 13:16
1

Python 3.4 comes with pip so you should be able to do the following in the command line:

python -m pip install geopy

If that doesn't work, try running this first:

python -m ensurepip
miles82
  • 6,584
  • 38
  • 28
  • Thanks for the help from yourself and @KieranBristow. The above advice has returned this: Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin pip install geopy File "", line 1 pip install geopy ^ SyntaxError: invalid syntax -m pip install geopy File "", line 1 -m pip install geopy ^ SyntaxError: invalid syntax -m ensurepip File "", line 1 -m ensurepip ^ SyntaxError: invalid syntax pip install geopy File "", line 1 pip install geopy SyntaxError: invalid syntax – user2020088 Oct 09 '14 at 12:08
  • That's because you started Python 2.7 which doesn't bundle pip like 3.4 does (and you obviously have both versions installed). Glad you got it working after all. – miles82 Oct 10 '14 at 05:49
1

Assuming you're trying to install on windows. This is how I have done. Prerequisite: pip (Else find here, how to install it)

  1. Step 1: Run cmd as Administrator
  2. Step 2: cd ..
  3. Step 3: cd .. // you're now in root
  4. Step 4: pip install geopy

Though it's been late to answer. Hope it helps somebody.

This is how you see it

Community
  • 1
  • 1
vishnu
  • 363
  • 3
  • 20