今天在使用 Pyinstaller 打包包含 Pathlib 的文件时报错。

这是源代码:
这是个修改当前文件夹下的图片格式的 exe。
# -*- coding:utf8 -*-
from pathlib import Path
from PIL import Image
import sys
path = Path(__file__).parent
for img_path in path.glob('*[!.exe]'
使用Pyinstaller打包Pathlib报错解决方案
在尝试使用Pyinstaller将包含Pathlib模块的Python脚本打包为exe时遇到了错误。问题在于`Path(__file__)`在打包后无法正常工作。通过引入sys库并使用`Path(sys.argv[0])`来获取脚本的绝对路径,成功解决了这个问题。这段代码主要功能是转换和缩放指定文件夹下的图片格式。
今天在使用 Pyinstaller 打包包含 Pathlib 的文件时报错。

这是源代码:
这是个修改当前文件夹下的图片格式的 exe。
# -*- coding:utf8 -*-
from pathlib import Path
from PIL import Image
import sys
path = Path(__file__).parent
for img_path in path.glob('*[!.exe]'
2897
2万+
1679

被折叠的 条评论
为什么被折叠?