Localization of Python Snaps

Hi all,

when I try to snap my application, which uses pythons gettext library for localization, the resulting snap exits with:
python UnicodeEncodeError: 'ascii' codec can't encode characters in position 79-80: ordinal not in range(128)

The application does run fine if not run from a snap and as far as I can see, this kind of error usually comes when the system encoding isn’t correct. Does snap packages don’t use utf-8 as default encoding?
Also I’ve tried adding export LOCPATH=${SNAP}/localedir to the launcher script in case there’s something wrong with the paths, but that haven’t changed anything.

Hey, I noticed this problem as well.

I was able to workaround this by adding

export LC_ALL=C.UTF-8

to the launcher (example).

But I’m wondering why it doesn’t default to UTF-8 too.

Are you using the system python or one in the snap?
How are you building the snap?

I have been using a part with plugin: python and built the snap using cleanbuild.

Whatever python script you are calling, is that through something setup through setup.py or something you manually crafted and added through a different part. If it is the latter, check the shebang and make sure it is using the correct one.

Mine is setup using setup.py and setuptools.

The addition of LC_ALL does fix my problem too. Thanks for that.

As for the other questions brought up, I’m using a custom plugin which inherits the python plugin and extends/changes it a bit. The script that causes the error is from the executable build with setup.py

Hi @sergiusens – This cost me probably 30m when I was packaging a couple simple python tools (this error of course leads you to think you messed something up in your string encoding/decoding) and I was wondering if it could get some more attention or even a workaround put in place inside snapcraft? It’s reported in bug:

I made this reproduction github in case anyone wanted to shortcut the problem.

https://github.com/dpb1/snapcraft-lcall-bug

:slight_smile: