问题描述
我正在使用Python 3.7.9程序(.py),该程序在CMD终端和PyCharm上运行时都可以正常运行(我正在使用reverse_geocoder模块-与错误有关)。然后,我使用pyinstaller将.py文件转换为.exe。我将文件放在dist文件夹中。但是,运行它时出现错误:
(我已将reverse_geocoder导入为rg-因为该错误会弹出)
Traceback (most recent call last):
File "myProgram.py",line 235,in <module>
location = reverseGeocode(coordinates)
File "myProgram.py",line 170,in reverseGeocode
result = rg.search(coordinates)
File "reverse_geocoder\__init__.py",line 292,in search
File "reverse_geocoder\__init__.py",line 88,in getinstance
File "reverse_geocoder\__init__.py",line 111,in __init__
File "reverse_geocoder\__init__.py",line 197,in extract
File "c:\users\USER\appdata\local\programs\python\@R_502_4402@7\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 0x81 in position 286: character maps to <undefined>
我曾尝试按照几个论坛问题的建议,在reverse_geocoder_ init _。py中的open()中添加encoding ='utf-8',但错误没有改变。 有人可以帮我吗?附言我是Python的初学者,因此请尽可能简化答案。
解决方法
我无法解决这个问题。相反,我决定使用Bing Reverse地理编码器,它解决了我的问题。有了更少的代码块,每月有了更多免费的API调用,这变得容易得多。