Forums

having trouble installing geopy and running it

Hi,

I am new to python and geopy and I was trying to install it on my Pythonanywhere. I created a folder where I have a set of files with latitudes and longitudes, then I followed the instructions and wrote this on a batch console

pip3.6 install geopy

and it looks like it is already installed I got the following Requirement already satisfied: geopy in /usr/local/lib/python3.6/dist-packages

However when I try to run some code like

 from geopy.geocoders import Nominatim
 geolocator = Nominatim()
 location = geolocator.geocode("175 5th Avenue NYC")
 print(location.address)

I get an error: "from: can't read /var/mail/geopy.geocoders"

Any help here highly appreciated

[edit by admin: formatting]

Could you give the complete stack trace?

you mean this

13:51 ~/octavio/Test/geopy $ pip3.6 install geopy                                                                                         
Requirement already satisfied: geopy in /usr/local/lib/python3.6/dist-packages
13:51 ~/octavio/Test/geopy $ from geopy.geocoders import Nominatim
from: can't read /var/mail/geopy.geocoders

[edit by admin: formatting]

Ah, I see the problem. You're in a bash console, not a Python one, when you run Python code it's getting interpreted by bash, which is trying to run a "from" command with the remainder of the line as its parameters -- which is why you're getting such a weird error message.

You need to run python3.6 before you enter the Python code.

For example:

18:12 ~$ pip3.6 install geopy
Requirement already satisfied: geopy in /usr/local/lib/python3.6/dist-packages
18:13 ~$ python3.6
Python 3.6.0 (default, Jan 13 2017, 00:00:00) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from geopy.geocoders import Nominatim
>>>

ok I tried running this file by saving it as a file like test.py and executing the code. it opened its own terminal but I still got an error

pip3.6 install geopy

from geopy.geocoders import Nominatim

geolocator = Nominatim()

location = geolocator.geocode("175 5th Avenue NYC")

print(location.address)

got the following error:

File "/home/atmi/octavio/Test/geopy/test.py", line 3 pip3.6 install geopy ^ IndentationError: unexpected indent

pip3.6 install geopy is not valid Python. Do not include it in your Python script.

Just to clarify -- you're mixing up two different languages here. Bash is the system command language -- the same as a command prompt on Windows or the Terminal on a Mac. You use it to configure the system, by installing packages. The command

pip3.6 install geopy

...is a bash command, so you run it in a bash console. It's not Python code. It should not go in your .py file.

The other code -- your stuff starting from geopy.geocoders import Nominatim is Python code. You run that from a file ending with .py.