Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loboere opened this issue Feb 14, 2023 · 56 comments
Open

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

loboere opened this issue Feb 14, 2023 · 56 comments

Comments

@loboere
Copy link

loboere commented Feb 14, 2023

Sometimes when I execute a cell this error appears, I must restart the execution environment to eliminate the error.


NotImplementedError Traceback (most recent call last)
in
----> 1 get_ipython().system('pip install ffmpeg-python')

2 frames
/usr/local/lib/python3.8/dist-packages/google/colab/_system_commands.py in _run_command(cmd, clear_streamed_output)
161 locale_encoding = locale.getpreferredencoding()
162 if locale_encoding != _ENCODING:
--> 163 raise NotImplementedError(
164 'A UTF-8 locale is required. Got {}'.format(locale_encoding))
165

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

@metrizable
Copy link
Contributor

@loboere Thanks for reporting the issue and thanks for using Colab. Can you provide a minimal reproducible notebook?

@mlp2501
Copy link

mlp2501 commented Feb 26, 2023

I got the same error .... any solution to this yet?

@dracifer
Copy link

the commands triggered this error for me

!pip install youtube-dl
!youtube-dl https://www.youtube.com/watch?v=ll8TgCZ0plk -f 22 -o video.mp4
!ffmpeg -i video.mp4 -t 00:00:06 -c:v copy video-clip.mp4

@karray
Copy link

karray commented Feb 27, 2023

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

@wahid028
Copy link

wahid028 commented Mar 2, 2023

@karray this solution works for me. Thanks a lot

@cperry-goog
Copy link

Thanks!

@Dannynis
Copy link

I also get this error randomly, If i have to guess its after alot of outputs that been written to the output screen

@victormurcia
Copy link

@karray this worked for me as well! Thanks!

@karray
Copy link

karray commented Mar 16, 2023

In my opinion, this issue shouldn't be closed yet. While the workaround offered may serve as a temporary solution, it doesn't actually address the underlying problem.

@TheWizier
Copy link

I agree with @karray This is not fixed and should be reopened. Encountered it just now myself.

@liujuncn
Copy link

I also get this error randomly these two days.

@xdevfaheem
Copy link

I didn't Encountered this Before. But these Week, These Happens Randomly Every now and Then...

@orhansonmeztr
Copy link

import locale
locale.getpreferredencoding = lambda: "UTF-8"

I got this error when I tried to install fasttext library in colab.
Your solution worked.
Thanks @karray

@anmorgan24
Copy link

I got this error when I tried to install torchvision in Colab. Thanks @karray solution worked perfectly!

@noobmldude
Copy link

The solution from @karray worked for me! Thanks!

@alonj
Copy link

alonj commented Jun 20, 2023

The same problem appears when trying to install sentencepiece. The solution from @karray works (thanks!), but breaks other dependencies in the code (such as importing the Transformers library).

@libTorrentUser
Copy link

libTorrentUser commented Jun 26, 2023

Got this error just now. Only went away after resetting the runtime.

@IIskel
Copy link

IIskel commented Jul 2, 2023

Thanks a lot it works for me.

@sef43
Copy link

sef43 commented Jul 4, 2023

I am encountering this error still. The posted workaround works for me.

@uddaloksarkar
Copy link

!pip install gmpy2 triggered the same error for me.
The solution worked. Thanks @karray

@Vasanthdata
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

It worked. Thank you!!

@mkmohangb
Copy link

I encountered this issue today. There is a SO issue on this from 2019.
https://stackoverflow.com/questions/56081324/why-are-google-colab-shell-commands-not-working

@cperry-goog cperry-goog reopened this Nov 16, 2023
@contractorwolf
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

this worked for me, thx @teddybear082

@Wb-az
Copy link

Wb-az commented Nov 22, 2023

I also got the same issue today after completing the training of yolov8 in Google Colab.

@javadr
Copy link

javadr commented Dec 4, 2023

I encountered the same problem while attempting to download Mozilla Common Voice using wget.
Thanks to @karray, his solution also resolved my issue!

@vx6122035
Copy link

vx6122035 commented Dec 10, 2023

I also got the same issue today after completing the training of yolov8 in Google Colab.

Same here. After a quite simple YOLOv8 training. Same issue.

from ultralytics import YOLO
model = YOLO('path/to/my/model.pt')
model.train(data='path/to/my/data.yaml', epochs=100, batch=16)

Besides, thank you so much @karray, your solution also resolved my issue!

@zelucena
Copy link

zelucena commented Jan 3, 2024

it happened all of a sudden for me... in an environment that had been been working for days. I can't even tell the steps to reproduce it
!pip install llama-index transformers accelerate bitsandbytes

@apandy02
Copy link

Is anyone trying to actively solve this?

@scalemailted
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

I just faced the same issue, and this temporary solution solved my problem.

@ashioyajotham
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

Thank you so much pal!

@SinaRanjkeshzade
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

This code worked for me, Thanks!

@AlvinKimata
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

This worked for me. Thanks!

@CNielsen94
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

Had the same encoding issue with a few notebooks.

This temporary fix worked. Thanks alot @karray!

@aycaecemgul
Copy link

I got this error as well, temporary fix solved it, but it's been a long time, shouldn't it be solved by now?

@petewarden
Copy link

Just another +1 to solving this error, since I'm also encountering it seemingly-randomly.

@dtch1997
Copy link

dtch1997 commented Apr 9, 2024

+1 to solving this, I can never tell when this is going to trigger and spoil my workflow.

@dtch1997
Copy link

dtch1997 commented Apr 9, 2024

I resolved this for myself in Python 3.10 with a small edit to @karray 's solution:

import locale
locale.getpreferredencoding = lambda _: "UTF-8"

The difference being that my library required local.get_preferredencoding to accept a boolean parameter.

@amian98
Copy link

amian98 commented Apr 11, 2024

I faced the same exception in pyannote.
I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.
Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

got another error saying something like : lambda() takes 0 positional arguments, 1 was given.

which changing code to

import locale
locale.getpreferredencoding = lambda x: "UTF-8"

fixed it

Thx a lot, it works for me

@marcospgp
Copy link

Just ran into this issue as well! Are there any plans for a fix?

@amian98
Copy link

amian98 commented Apr 17, 2024

Just ran into this issue as well! Are there any plans for a fix?

Check the latest comments in this thread, there are a couple of variants of the solution for that error depending on the use case. It worked for me

@mikemhenry
Copy link

mikemhenry commented Apr 19, 2024

It would be great if this could get fixed since I've got a notebook that needs both fixes locale.getpreferredencoding = lambda: "UTF-8" and locale.getpreferredencoding = lambda _: "UTF-8" depending on the cell 🙃

@pooyaEst
Copy link

It would be great if this could get fixed since I've got a notebook that needs both fixes locale.getpreferredencoding = lambda: "UTF-8" and locale.getpreferredencoding = lambda _: "UTF-8" depending on the cell 🙃

def return_utf_8(input=None):
    return "UTF-8"
locale.getpreferredencoding = return_utf_8

@alexfritsch10
Copy link

@karray Not all heroes wear capes!

@jernland0279
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

The code from @pooyaEst works also for me.

@WawanFirgiawan
Copy link

I faced the same exception in pyannote.

I solved it by overriding locale.getpreferredencoding:

import locale
locale.getpreferredencoding = lambda: "UTF-8"

Here is a notebook with the workaround.

Update: While many people have found this workaround helpful, it is important to note that it should be regarded as a temporary solution and not considered a permanent fix.

Thank you mr. I think this best solution this probel

@mischa-robots
Copy link

It's 2025 and the same error happens for me when I install Ultralytics Yolo:

!pip install -q ultralytics
from ultralytics import YOLO

Creating new Ultralytics Settings v0.0.6 file ✅
View Ultralytics Settings with 'yolo settings' or at '/root/.config/Ultralytics/settings.json'
Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.
Downloading https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m.pt to 'yolo11m.pt'...
100%|██████████| 38.8M/38.8M [00:00<00:00, 41.4MB/s]
Ultralytics 8.3.72 🚀 Python-3.11.11 torch-2.5.1+cu124 CUDA:0 (Tesla T4, 15095MiB)
engine/trainer: task=detect, ...
Downloading https://ultralytics.com/assets/Arial.ttf to '/root/.config/Ultralytics/Arial.ttf'...

The workaround helps 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests