I am trying to run my python file in a docker container.
I am using NVIDIA container image for PyTorch, release 19.05, which provides Ubuntu 16.04 including Python 3.6 environment.
According to another similar question, I have added the environment parameter -e PYTHONIOENCODING=utf-8
when I ran the docker image:
nvidia-docker run -dit --name teddy -p 8122:22 -e PYTHONIOENCODING=utf-8 1e0071d37342
Although I have checked the locale in the container which seems correct:
root@ce83e4a4301a:/workspace# locale
LANG=
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=C.UTF-8
I still got the error:
root@ce83e4a4301a:/workspace/paddlespeech/examples/other/tts_finetune/tts3# ./run_en.sh
check oov
Traceback (most recent call last):
File "local/check_oov.py", line 240, in <module>
lang=args.lang)
File "local/check_oov.py", line 161, in get_check_result
pronunciation_phones = get_pronunciation_phones(lexicon_file)
File "local/check_oov.py", line 99, in get_pronunciation_phones
for line in f2.readlines():
File "/opt/conda/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 6269: ordinal not in range(128)
(The code is fine when it is run in the same machine but not in the container.)
And I checked the code:
...
with open(lexicon_file, "r") as f2:
for line in f2.readlines():
...
However, the problem was fixed by manually adding the argument encoding="utf-8"
as follows:
...
with open(lexicon_file, "r", encoding="utf-8") as f2:
for line in f2.readlines():
...