即使在安装pip之后也无法将geopy导入Jupyter [英] Unable to import geopy into Jupyter even after pip installation
问题描述
我正在尝试安装geopy以在Jupyter中使用,但是当我尝试导入它时,我一直收到以下错误消息.
I'm trying to install geopy to use in Jupyter, but I keep getting the following error when I try to import it.
import geopy
ModuleNotFoundErrorTraceback (most recent call last)
<ipython-input-1-3fa4a0b62b91> in <module>
1 import pandas as pd
2 import numpy as np
----> 3 import geopy
4
5 # Suppressing warnings
ModuleNotFoundError: No module named 'geopy'
我已经使用pip install geopy
安装了geopy,所以我不确定为什么会出现此错误.
I already installed geopy using pip install geopy
so I'm not sure why I'm getting this error.
在命令行中输入pip --version
时,我得到:
In command line when input pip --version
I get:
pip 19.0.3 from /Library/Python/2.7/site-packages/pip-19.0.3-py2.7.egg/pip (python 2.7)
当我输入pip list
时:
Package Version
-------------------------------------- --------
altgraph 0.10.2
bdist-mpkg 0.5.0
bonjour-py 0.3
geographiclib 1.49
geopy 1.18.1
macholib 1.5.1
matplotlib 1.3.1
modulegraph 0.10.4
numpy 1.8.0rc1
pip 19.0.3
py2app 0.7.3
pyobjc-core 2.5.1
pyobjc-framework-Accounts 2.5.1
pyobjc-framework-AddressBook 2.5.1
pyobjc-framework-AppleScriptKit 2.5.1
pyobjc-framework-AppleScriptObjC 2.5.1
pyobjc-framework-Automator 2.5.1
pyobjc-framework-CFNetwork 2.5.1
pyobjc-framework-Cocoa 2.5.1
pyobjc-framework-Collaboration 2.5.1
pyobjc-framework-CoreData 2.5.1
pyobjc-framework-CoreLocation 2.5.1
pyobjc-framework-CoreText 2.5.1
pyobjc-framework-DictionaryServices 2.5.1
pyobjc-framework-EventKit 2.5.1
pyobjc-framework-ExceptionHandling 2.5.1
pyobjc-framework-FSEvents 2.5.1
pyobjc-framework-InputMethodKit 2.5.1
pyobjc-framework-InstallerPlugins 2.5.1
pyobjc-framework-InstantMessage 2.5.1
pyobjc-framework-LatentSemanticMapping 2.5.1
pyobjc-framework-LaunchServices 2.5.1
pyobjc-framework-Message 2.5.1
pyobjc-framework-OpenDirectory 2.5.1
pyobjc-framework-PreferencePanes 2.5.1
pyobjc-framework-PubSub 2.5.1
pyobjc-framework-QTKit 2.5.1
pyobjc-framework-Quartz 2.5.1
pyobjc-framework-ScreenSaver 2.5.1
pyobjc-framework-ScriptingBridge 2.5.1
pyobjc-framework-SearchKit 2.5.1
pyobjc-framework-ServiceManagement 2.5.1
pyobjc-framework-Social 2.5.1
pyobjc-framework-SyncServices 2.5.1
pyobjc-framework-SystemConfiguration 2.5.1
pyobjc-framework-WebKit 2.5.1
pyOpenSSL 0.13.1
pyparsing 2.0.1
python-dateutil 1.5
pytz 2013.7
scipy 0.13.0b1
setuptools 18.5
six 1.4.1
xattr 0.6.4
推荐答案
好的,我在做一个训练计划时有点头疼,而正在展示的那个人并没有那么准确.
OK I had a bit of a headache with this as I was doing a training program and the guy who was showing did not have it accurate.
以下是一些链接和建议以尝试修复.我在为Jupyter Notebook使用Anaconda.
Here are some links and suggestions to try to fix. I was using Anaconda for the Jupyter Notebook.
来自" https://groups.google .com/a/continuum.io/forum/#!topic/anaconda/pqFuJBDcBb4 ",其中最后一条注释是该命令.
From "https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/pqFuJBDcBb4" one of the last comments had the command.
因此,只需以管理员身份打开Anaconda CLI提示符.
So just open Anaconda CLI prompt as Administrator.
conda install -c conda-forge geopy
完成操作后,必须确保使用正确的语法,因为其中某些语法已从此处的教程"中进行了更改.这是一个很好的解释: https://github.com/geopy/geopy
Once you have done that you have to ensure you are using the right syntax as some of it has changed from the "tutorials" out there. Here is a great explanation: https://github.com/geopy/geopy
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="My_geolocate")
lookingFor = "Moscow"
locations = geolocator.geocode(lookingFor)
print(locations)
结果:
找到莫斯科
Москва,Центральныйфедеральныйокруг,Россия
Москва, Центральный федеральный округ, Россия
如果您想返回英文位置:
If you want returned location in English:
locations = geolocator.geocode(lookingFor, language="en")
参考: https://anaconda.org/conda-forge/geopy https://github.com/geopy/geopy
这篇关于即使在安装pip之后也无法将geopy导入Jupyter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!