使用geograpy(Python)从文本中提取城市时出现错误

时间:2019-02-15 22:45:55

标签: python windows nltk geography

我正在尝试从文本中提取城市名称,但出现错误。 这是我的代码:

import geograpy

text = 'I am from Delhi'

places = geograpy.get_place_context(text=text)

print(places.cities)

错误:

Traceback (most recent call last):

  File "C:/Users/M.B.C. Kadawatha/PycharmProjects/NewsFeed/NLP.py", line 17, in <module>
    places = geograpy.get_place_context(text=text)

  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\__init__.py", line 11, in get_place_context
    pc.set_cities()

  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\places.py", line 137, in set_cities
    self.populate_db()
  File "C:\Users\M.B.C. Kadawatha\PycharmProjects\NewsFeed\venv\lib\site-packages\geograpy\places.py", line 30, in populate_db
    for row in reader:
  File "C:\Users\M.B.C. Kadawatha\AppData\Local\Programs\Python\Python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 274: character maps to <undefined>

1 个答案:

答案 0 :(得分:0)

这应该是软件包this.$options.__proto__.components['MyComponent1'] 中的错误。

geograpy中,进行修订:

geograpy/places.py

with open(cur_dir+"/data/GeoLite2-City-Locations.csv", "rb") as info:

编码问题应该消失了。