使用地理学(Python)从文本中提取城市时出错

问题描述 投票:0回答:1

我试图从文本中提取城市名称,但它给出了一个错误。这是我的代码:

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>
python windows nltk geography
1个回答
0
投票

这应该是包geograpy中的一个错误。

geograpy/places.py,修改:

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

with open(cur_dir+"/data/GeoLite2-City-Locations.csv", "r", encoding="utf-8") as info:

编码问题应该消失。

© www.soinside.com 2019 - 2024. All rights reserved.