如果程序与 PyInstaller 一起打包,则 Pathlib 在 Unicode-Symbol 上崩溃

问题描述

我的python程序创建了一个文件

output_file_path = Path(output_folder_path,filename)

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

请注意,文件名包含 German-unicode-characters。 如果我在 PyCharm 中执行此操作,则一切正常。

但是,当且仅当我创建一个可执行文件

 python3 -m PyInstaller --onefile main.py

然后在执行时会引发:

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

这要么是我的代码、pathlib、pyinstaller 的问题,要么是我组合它们的方式。

编辑:我被要求提供一个最小的可重复示例:

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

upper 语句在 PyCharm 中有效,但在打包程序中引发异常。

我该如何解决这个问题?

(我更愿意“正确”执行此操作,而不仅仅是删除所有 unicode 字符。)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)