python - 运行 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的初学者,所以请尽可能简化答案。
解决方案
我无法解决这个问题。相反,我决定使用 Bing 反向地理编码器,它解决了我的问题。这要容易得多,代码块更小,每月免费 API 调用更多。
推荐阅读
- pyqt5 - 从 .ui 转换为 .py 后 PyQt5 窗口缩小
- c# - 实体框架扩展批量插入和重复记录
- html - 位置:粘性仅适用于右侧
- java - 包含所有没有空值的对象属性的字符串
- c# - 滑块不统一发送信息
- kubernetes - 为什么 Kubernetes 中的 coredns 无法解析 Pod DNS 记录
- java - 如何在不重新启动服务器的情况下使用功能或更改来更新服务器
- python-3.x - 启动 pyspark-shell 给 env jupyter no such file error in mac
- asp.net - 如何从 URL 中隐藏 ActionLink 参数或 queryString?
- vue.js - Vue js - 根据当前时间显示列表中的元素