首页 > 解决方案 > 运行 Python 转换的 exe 时出错:“UnicodeDecodeError: 'charmap' codec can't decode byte” using reverse_geocoder

问题描述

我正在开发一个 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\python37\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>

我尝试按照几个论坛问题的建议将 encoding='utf-8' 添加到 reverse_geocoder_init _.py 中的 open() 但错误没有改变。有人可以帮帮我吗?PS我是Python的初学者,所以请尽可能简化答案。

标签: pythonpython-3.xunicodepython-3.7reverse-geocoding

解决方案


我无法解决这个问题。相反,我决定使用 Bing 反向地理编码器,它解决了我的问题。这要容易得多,代码块更小,每月免费 API 调用更多。


推荐阅读