pythonlocalegoogle-colaboratoryturi-create

Why are Google Colab shell commands not working?


Steps to reproduce:

Open new Colab notebook on GPU

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

I get the following error:

---------------------------------------------------------------------------
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

Unfortunately of which makes little sense to me why this is occurring. Any leads? I will also post as a potential issue in the turicreate project.

EDIT:

It does look like it's overriding my locale as suggested in the comments. Before importing I can do:

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

But after I get:

locale.getdefaultlocale()
(None, None)

Though I'm not sure how to reset the locale now that I've lost the use of shell commands?


Solution

  • This is an issue with Turicreate. The relevant issue is opened here: https://github.com/apple/turicreate/issues/1862

    The summary is: On startup turicreate sets the LC_ALL environment variable to C ().

    The workaround for this:

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