【问题标题】:python 2.7 cannot import geocoder librarypython 2.7 无法导入地理编码器库
【发布时间】:2017-08-15 14:37:27
【问题描述】:

win32 上的 Python 2.7.10。视窗 8.1

使用pip安装geocoder库https://pypi.python.org/pypi/geocoder/1.8.0

尝试导入库时出现此错误

>>> import geocoder
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\__init__.py", line 36, in <module>
    from geocoder.api import get, yahoo, bing, geonames, mapquest, google, mapbox  # noqa
  File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\api.py", line 29, in <module>
    from geocoder.freegeoip import FreeGeoIP
  File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\freegeoip.py", line 6, in <module>
    import ratelim
  File "C:\Python27\ArcGIS10.4\lib\site-packages\ratelim\__init__.py", line 6, in <module>
    from decorator import decorator
ImportError: No module named decorator
>>> 

我认为只需安装装饰器库就可以解决问题,但该库已经安装了

C:\Python27\ArcGIS10.4\Scripts>pip install decorator
Requirement already satisfied: decorator in c:\python27\arcgis10.4\lib\site-packages

更新

C:\Users\rizagha>python --version
Python 2.7.10

C:\Users\rizagha>python
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from decorator import decorator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named decorator

可能使这复杂化的事情是我通过 arcgis 安装了 python 32 位和 64 位...

【问题讨论】:

  • 在你的命令行输入 python --version,如果是 2.7 则进入 python 解释器并尝试手动输入 from decorator import decorator
  • 嗯所以检查我的编辑,那个模块没有导入..

标签: python windows python-2.7 geocoding


【解决方案1】:

尝试运行以下命令安装模块

[root@server] python -m pip install decorator

这应该将模块安装到运行 python 命令时启动的解释器的 python 库中

然后尝试再次启动您的解释器并尝试导入模块(假设它没有说它已经满足)

[root@server] python
>> from decorator import decorator
>>

如果它确实说它已经满足了,那么你可以尝试使用 pip 卸载它,然后通过显式指定 python -m 命令重新安装它

[root@server] pip uninstall decorator
[root@server] python -m pip install decorator

然后您可以检查该模块是否在您的默认解释器中可用

[root@server] python
>> from decorator import decorator
>>

【讨论】:

  • 不行,说装饰器的要求已经满足,但是当我导入模块时它说它不存在
  • 尝试执行 pip 卸载(无需显式键入 python -m),然后尝试使用 python -m pip install decorator 重新安装它
  • 太棒了!重写你的答案,这样我就可以排除它了!
猜你喜欢
  • 2021-12-03
  • 2011-04-29
  • 2015-09-13
  • 2013-02-27
  • 1970-01-01
  • 2012-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多