簡體   English   中英

運行 Python 轉換后的 exe 時出錯:“UnicodeDecodeError:‘charmap’編解碼器無法解碼字節”使用 reverse_geocoder

[英]Error when running Python converted 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>

我嘗試按照幾個論壇問題的建議在 reverse_geocoder_ init _.py 中將 encoding='utf-8' 添加到 open(),但錯誤沒有改變。 有人可以幫幫我嗎? PS 我是 Python 的初學者,所以請盡可能簡化答案。

我無法解決這個問題。 相反,我決定使用 Bing 反向地理編碼器,它解決了我的問題。 這要容易得多,代碼塊更小,每月有更多免費 API 次調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM