【发布时间】:2021-08-17 19:28:18
【问题描述】:
我编写了一个程序来遍历文件夹中的文件,并将“.jpg”文件扩展名添加到所有文件,而没有任何文件扩展名。我在我的电脑上测试了这个程序,到目前为止它可以工作。 我使用 auto-py-to-exe 包将 .py 文件编译为 .exe 文件,以将程序发送给她的计算机上没有安装 python 的朋友。 当我测试 .exe 文件时,我发现程序的行为不同并且不再工作了。 以下代码是我写的,如果你取消注释打印命令你可以在运行.py和.exe文件时看到不同的文件
import os
files = os.listdir(os.path.dirname(os.path.abspath(__file__)))
for file in files:
# print(file)
split_tup = os.path.splitext(file)
if split_tup[1] == '':
os.rename(file, file + '.jpg')
# The input is just that the console doesn't shut down
a = input()
对于 auto-py-to-exe,我使用了以下命令:
pyinstaller --noconfirm --onefile --console "C:/mypath/jpg_wizard.py"
有没有办法可以更改 auto-py-to-exe 命令/设置或替代代码,以便能够将程序作为 .exe 文件运行并获得与 .py 文件相同的结果?
【问题讨论】:
-
也许你应该 chdir 进入
os.path.dirname(os.path.abspath(__file__))?看起来像一个相对路径问题。 -
我添加了
print(os.getcwd())来查看工作目录。它与我正在使用的路径匹配,所以这不是我想的问题 -
您能否提供有关“程序行为不同且不再工作”的详细信息?
标签: python operating-system auto-py-to-exe