Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 308
Frankie Avatar asked Sep 04 '25 16:09

Frankie


1 Answers

I got a different work around from a similar issue

First to check of the the current locale:

import locale
print(locale.getpreferredencoding())

The work around is to create a function that returns the required local i.e. UTF-8

import locale
def getpreferredencoding(do_setlocale = True):
    return "UTF-8"
locale.getpreferredencoding = getpreferredencoding

References:
OS module UTF Mode
Locale module

like image 165
Stephen Ng'etich Avatar answered Sep 07 '25 16:09

Stephen Ng'etich