Pathlib crashes on Unicode-Symbol iff program is packaged with PyInstaller

Viewed 78

My python-program creates a lockfile:

output_file_path = Path(output_folder_path, filename)

Path(output_file_path.as_posix() + ".lock").touch()

Note, that the filename contains german-unicode-characters. If I execute this in PyCharm, everything works just fine.

However, if and only if I create an executable with:

 python3 -m PyInstaller --onefile main.py

Then on execution this will raise a:

File "pathlib.py", line 1295, in touch
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 57: ordinal not in range(128)

This is either an issue with my code, pathlib, pyinstaller or the way I'm combining them.

EDIT: I have been asked to provide a minimal reproducible example:

from pathlib import Path
Path("/tmp/", "This should be a valid file: üöä").touch()

The upper statement works in PyCharm, but raises an exception in a packaged program.

How do I fix this?

(I'd prefer to do this "properly" and not just simply delete all unicode chars.)

0 Answers
Related