
我正在嘗試在資料處理(linux)叢集上執行 python 程式。如果我從 Linux 桌面 ssh 到叢集並啟動它,程式運行正常,但如果我從 mac 筆記型電腦 ssh 到叢集並嘗試運行它,程式就會失敗,我收到以下錯誤:
[muzzle@cluster]~% acme-calibrate detector DARK --in-folder /gpfs/acme/exp/instrument/201802/experiment1/raw --out-folder /home/muzzle/dark_out --run 28
Traceback (most recent call last):
File "/home/boff/calframework/framework/extern/bin/acme-calibrate", line 11, in <module>
load_entry_point('acme-Offline-Calibration', 'console_scripts', 'acme-calibrate')()
File "/home/boff/calframework/framework/extern/lib/python3.4/site-packages/setuptools-39.1.0-py3.4.egg/pkg_resources/__init__.py", line 480, in load_entry_point
File "/home/boff/calframework/framework/extern/lib/python3.4/site-packages/setuptools-39.1.0-py3.4.egg/pkg_resources/__init__.py", line 2691, in load_entry_point
File "/home/boff/calframework/framework/extern/lib/python3.4/site-packages/setuptools-39.1.0-py3.4.egg/pkg_resources/__init__.py", line 2322, in load
File "/home/boff/calframework/framework/extern/lib/python3.4/site-packages/setuptools-39.1.0-py3.4.egg/pkg_resources/__init__.py", line 2328, in resolve
File "/home/boff/pycalibrate_tmp/acme_calibrate/calibrate.py", line 236, in <module>
nb = nbformat.read(f, as_version=4)
File "/home/boff/calframework/framework/extern/lib/python3.4/site-packages/nbformat/__init__.py", line 141, in read
return reads(fp.read(), as_version, **kwargs)
File "/home/boff/calframework/framework/extern/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 150: ordinal not in range(128)
它似乎與從 UTF 到 ASCII 的一些轉換有關,但我超出了我的深度。
我在terminal.app 和iterm2 上都遇到同樣的錯誤。順便說一句,我曾經安裝過 iterm2 shell 集成,但現在已將其刪除。
筆記型電腦上的區域設定是:
$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
遠端伺服器上的區域設定是:
% locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
這是我的 Linux 桌面上的區域設置,它與叢集的區域設置相同:
$ locale
LANG=en_GB.UTF-8
LANGUAGE=en_GB:en
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=
答案1
看起來正確的解決方案是在終端高級選項中取消設定“啟動時設定區域設定環境變數”,如中所述https://blog.remibergsma.com/2012/07/10/setting-locales- Correctly-on-mac-osx-terminal-application/
要在 iterm2 上執行相同的操作,您必須取消選擇“首選項”>“設定檔”>“終端”>“自動設定區域設定變數”,如這裡所述https://apple.stackexchange.com/questions/83428/lang-variable-wrong-in-iterm2-wheres-the-bug
答案2
貼文 OS X 終端 UTF-8 問題 有一些有用的建議,基於 幫助設定終端應用程式的指南:
在終端機->首選項->設定->高級:
在下面國際的,確保字元編碼設定為統一碼 (UTF-8)。
在下面模擬, 確保這件事使用 Control-V 轉義非 ASCII 輸入是不是放。
這本身可能就足以解決問題。
使用該命令
locale
並查看LC_CTYPE
應以 結尾的行.UTF-8
。如果沒有,則在 bash.profile
或.bashrc
主目錄中加入如下行:export LC_CTYPE=your-locale-here.UTF-8
將以下行新增至
.inputrc
主目錄(如果需要,請建立它):set meta-flag on set input-meta on set output-meta on set convert-meta off
您需要重新啟動 bash 才能使新設定生效。