question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Traceback when locale not set to UTF-8

See original GitHub issue

On a machine where the locale has not been set to UTF-8 you get tracebacks when installing/running pipx. E.g. when installing:

Traceback (most recent call last):
  File "get-pipx.py.1", line 287, in <module>
    main()
  File "get-pipx.py.1", line 283, in main
    print(f"Enjoy! {'\u2728 \U0001f31f \u2728' if not WINDOWS else ''}")
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2728' in position 7: ordinal not in range(256)

Or when installing a package:

ipx install poetry
zsh: correct 'pipx' to 'popd' [nyae]? n
2nstalling package 'poetry'       
  installed package poetry 0.12.11, Python 3.6.7
  These binaries are now globally available
    - poetry
Traceback (most recent call last):
  File "/home/pmav2/.local/bin/pipx", line 10, in <module>
    sys.exit(cli())
  File "/home/pmav2/.local/pipx/venvs/pipx-app/lib/python3.6/site-packages/pipx/main.py", line 932, in cli
    run_pipx_command(args)
  File "/home/pmav2/.local/pipx/venvs/pipx-app/lib/python3.6/site-packages/pipx/main.py", line 642, in run_pipx_command
    force=args.force,
  File "/home/pmav2/.local/pipx/venvs/pipx-app/lib/python3.6/site-packages/pipx/main.py", line 505, in install
    print(f"done! {stars}")
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2728' in position 6: ordinal not in range(256)

Obviously, the problem is the special characters in the print statements. My guess is that you could check sys.getdefaultencoding() before you actually try to print them.

If you want to test this, on ubuntu you can set an “ansi” encoding with:

sudo update-locale LANG=en_US

and restore utf-8 with:

sudo update-locale LANG=en_US.UTF-8

You probably need to open a new terminal after each change though.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
jsoutherlandcommented, Jan 22, 2021

It looks like it’s possible to avoid these issues by disabling emojis like this:

USE_EMOJI=false python3 -m pipx ensurepath

2reactions
uranusjrcommented, Feb 2, 2021

I filed #619 to mention a pip upgrade may be required to install pipx.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python locale error: unsupported locale setting - Stack Overflow
I had this problem when using inside a Docker container. I solved by installing locales, adding my language to the locale.gen file, executing ......
Read more >
Traceback when locale not set to UTF-8 · Issue #73 · pypa/pipx
On a machine where the locale has not been set to UTF-8 you get tracebacks when installing/running pipx. E.g. when installing: Traceback (most...
Read more >
How to fix locale.Error: unsupported locale setting in Python
The first two commands set the LC_ALL and LC_CTYPE environment variables, then the third one commits the changes to the system. After running ......
Read more >
Python locale error: unsupported locale setting
Run following commands to get rid of locale.error: unsupported locale setting export LC_ALL="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8".
Read more >
[Windows] test__locale fails on Windows local machines
Error: unsupported locale setting # It works using the low-level _locale module # which doesn't parse setlocale() output >>> import _locale ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found