新版 Python 在 PyCharm 無法正確判讀與除錯處理


Posted by monoserve174 on 2023-07-05

新版 Python 在 PyCharm 無法正確判讀與除錯處理

最近遇到 Python3.10 無法在 Pycharm 中正確判讀,雖然 Terminal 中直接下 python 指令還是能正常執行,但無法使用 Pycharm 的執行(Run)與除錯(Debug)等功能。

錯誤樣式 [unsupported] Python 3.1

出現此項錯誤主要原因為當前 Pycharm 版本過低,更新至 Pycharm 2022 後版本即可解決。
只要更新就可以解決位麼要開這篇文章呢,因為更新後會有連帶發生的問題

無法使用 Pycharm 執行或除錯

錯誤樣式 Fatal Python error: init_stdio_encoding: failed to get the Python codec name of the stdio encoding

Fatal Python error: init_stdio_encoding: failed to get the Python codec name of the stdio encoding

Python runtime state: core initialized

LookupError: unknown encoding: x-windows-950

Current thread 0x0000bd9c (most recent call first):

<no Python frame>

出現此項錯誤主要原因是當前編譯器預設或文件編碼無法正確判讀,需要調整編碼,在 PyCharm 中與相關資訊都是直接調整設定,調整路徑為 File > Settings > Editor > File Encodeings 調整

  • Global Encoding 為 UTF-8
  • Project Encoding 為 UTF-8
  • Create UTF-8 files 為 with NO BOM
    但...人生就是這個 But ,筆者嘗試後都是無法解決的,如果你跟筆者一樣,則須修改 PyCharm 的 vmoptions ,此檔案通常落在 C:\Program Files\JetBrains\PyCharm <Version>\bin 中的 pycharm64.exe.vmoptions,可以使用記事本打開後在最後一列新增
-Dfile.encoding=UTF-8

即可解決。

錯誤樣式 C:\Program Files\Python<Version>\python.exe: can't open file 'C:\Program': [Errno 2] No such file or directory

沒錯....就是你改完上面後卻發現... Pycharm 無法正確讀取資料夾了,此時是因為無論 PyCharm 在做執行或者除錯時會依賴本身的 pydevd.py 檔案,但因資料夾無法正確判讀,因此無法使用,那處理這點要求就只能在安裝 Pycharm 時的路徑不能有空白或者是中文字符。以下提供不重新安裝 PyCharm 的方式,首先先確認你安裝 Pycharm 的路徑,通常是 C:\Program Files\JetBrains\PyCharm <Version>,後面簡稱 PyCharm Path
接著使用命令提示字元 cmd

mklink /J C:\Pycharm "<PyCharm Path\>"

最後把 C:\Pycharm\bin 中的 pycharm64.exe 拉到桌面建立捷徑即可解決。


#Python #pycharm #Dev Env #debug







Related Posts

[JS] 關於Event Loop的一些名詞

[JS] 關於Event Loop的一些名詞

[Golang] strconv

[Golang] strconv

指定安裝程式版本號

指定安裝程式版本號


Comments