为什么 Google Colab shell 命令不起作用?

Why are Google Colab shell commands not working?

重现步骤:

在 GPU 上打开新的 Colab 笔记本

!ls #works
!pip install -q turicreate
import turicreate as tc
!ls #doesn't work

我收到以下错误:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-22-16fdbe588ee8> in <module>()
----> 1 get_ipython().system('ls')
      2 # !nvcc --version

2 frames
/usr/local/lib/python3.6/dist-packages/google/colab/_system_commands.py in _run_command(cmd, clear_streamed_output)
    165   if locale_encoding != _ENCODING:
    166     raise NotImplementedError(
--> 167         'A UTF-8 locale is required. Got {}'.format(locale_encoding))
    168 
    169   parent_pty, child_pty = pty.openpty()

NotImplementedError: A UTF-8 locale is required. Got ANSI_X3.4-1968

不幸的是,我不明白为什么会发生这种情况。有线索吗?我还将 post 作为 turicreate 项目中的一个潜在问题。

编辑:

它看起来确实像评论中建议的那样覆盖了我的语言环境。在导入之前我可以做:

import locale
locale.getdefaultlocale()
(en_US, UTF-8)

但是在我得到之后:

locale.getdefaultlocale()
(None, None)

虽然我现在已经无法使用 shell 命令,但我不确定如何重置语言环境?

这是 Turicreate 的问题。 相关issue在这里打开:https://github.com/apple/turicreate/issues/1862

摘要是:启动时turicreate sets the LC_ALL environment variable to C ()

解决方法:

import turicreate as tc
import os
del os.environ['LC_ALL']