14

currently I need to make some distance calculation. For this I am trying the following on my ipython-notebook (version 4.0.4):

from geopy.distance import vincenty

ig_gruendau = (50.195883, 9.115557)
delphi = (49.99908,19.84481)

print(vincenty(ig_gruendau,delphi).miles)

Unfortunately I receive the following error when running the code above: ImportError: No module named 'geopy'

Since I am pretty new at python, I wonder how can I install this module (without admin rights) or what other simple options I do have for this calculations?

Thanks, ML

user5446609
  • 174
  • 1
  • 1
  • 7
  • 1
    This error indicates that you do not have the geopy package installed. On a console (e.g. `bash` if you work on linux) execute the following command to install it `pip install geopy --user`. – Antonio Ragagnin Mar 17 '16 at 15:13
  • activating the python environment and then installing geopy, solved the issue for me – Boshra Jaber Oct 02 '22 at 10:16

3 Answers3

21

You need to install the missing module in your python installation. So you have to run the command:

pip install geopy

in your terminal. If you don't have pip, you'll have to install it using:

easy_install pip

and if both command fail with Permission denied, then you'll have to either launch the command as root:

sudo easy_install pip
sudo pip install geopy

or for pip, install it only for your user:

pip install geopy --user

And for future reference, whenever you get that kind of error:

ImportError: No module named 'XXXXX'

you can search for it on pypi using pip:

% pip search XXXXX

and in your case:

% pip search geopy
tornado-geopy (0.1.0)  - tornado-geopy is an asynchronous version of the awesome geopy library.
geopy.jp (0.1.0)       - Geocoding library for Python.
geopy.jp-2.7 (0.1.0)   - Geocoding library for Python.
geopy (1.11.0)         - Python Geocoding Toolbox

HTH

zmo
  • 24,463
  • 4
  • 54
  • 90
0

Even if you install using pip install command you still have to use:

conda install -c conda-forge geopy

This command is in the anaconda server so that it gets installed in the anaconda.

benson23
  • 16,369
  • 9
  • 19
  • 38
0

Double-check your interpreter settings.

Adding a potential solution below, especially for those running venvs through VS Code. A fresh VSC install put me back to square 1 with a number of "No Module Named" errors, which landed me on this thread.

My solution:

  1. update python/PIP as covered above
  2. enable official Python extension for VSC--not Code Runner (as I've seen suggested in a few places<< not bashing code runner--it's just that Python extension will get you going faster, especially if you're newer to development like me.
  3. Make sure your shell is activated, usually env/bin/activate, poetry shell, etc.
  4. Set your interpreter. VSC confuses folks by placing a recommendation 'star' next to your latest system/pip version of Python. If you're running a venv, be sure to select the Python version installed within your virtual environment.

enter image description here

Hope this helps--

OptoNPO
  • 91
  • 1
  • 3