英文:
Python application for renaming PDF files not working after conversion to executable (.exe)
问题
I'm working on a Python application that renames PDF files based on certain criteria. I use PySide6 for the GUI, and the application is supposed to read PDF files from a directory and rename them.
Here is the snippet that reads the PDF files from a directory:
directory = os.path.dirname(os.path.realpath(__file__))
Option 1
files = [entry.name for entry in os.scandir(self.directory) if entry.is_file() and entry.name.endswith(".pdf")]
Option 2
files = [f for f in os.listdir(self.directory) if os.path.isfile(os.path.join(self.directory, f)) and f.endswith(".pdf")]
Both options work perfectly when I run my script through Python. The renaming part is done through the following code:
if date_str:
new_file = os.path.join(self.directory, f"{date_str} - {file}")
os.rename(file_path, new_file)
The issue I'm facing is when I convert my script to an executable using either auto-py-to-exe or Nuitka. The executable launches just fine with both tools, and the PySide6 GUI opens up, but it seems to be unable to find any PDF files and doesn't rename anything. There are no errors displayed; it just doesn't perform the expected actions.
python -m nuitka --onefile --follow-imports --windows-disable-console --enable-plugin=pyside6 PDFRenamer.pyw
For context, I'm executing the .exe in the same directory as my .pyw file.
What could be causing this issue? How can I debug or resolve this? Any help or suggestions are highly appreciated.
Python Version 3.11.4
Thank you in advance!
英文:
I'm working on a Python application that renames PDF files based on certain criteria. I use PySide6 for the GUI, and the application is supposed to read PDF files from a directory and rename them.
Here is the snippet that reads the PDF files from a directory:
directory = os.path.dirname(os.path.realpath(__file__))
Option 1
files = [entry.name for entry in os.scandir(self.directory) if entry.is_file() and entry.name.endswith(".pdf")]
Option 2
files = [f for f in os.listdir(self.directory) if os.path.isfile(os.path.join(self.directory, f)) and f.endswith(".pdf")]
Both options work perfectly when I run my script through Python. The renaming part is done through the following code:
if date_str:
new_file = os.path.join(self.directory, f"{date_str} - {file}")
os.rename(file_path, new_file)
The issue I'm facing is when I convert my script to an executable using either auto-py-to-exe or Nuitka. The executable launches just fine with both tools and the PySide6 GUI opens up, but it seems to be unable to find any PDF files and doesn't rename anything. There are no errors displayed, it just doesn't perform the expected actions.
python -m nuitka --onefile --follow-imports --windows-disable-console --enable-plugin=pyside6 PDFRenamer.pyw
For context, I'm executing the .exe in the same directory as my .pyw file.
What could be causing this issue? How can I debug or resolve this? Any help or suggestions are highly appreciated.
Python Version 3.11.4
Thank you in advance!
答案1
得分: 0
directory = os.getcwd()
在运行应用程序作为独立的 .exe 文件时也可以工作。使用 PyInstaller,甚至在没有 AV 报警的情况下也可以工作。
英文:
directory = os.getcwd()
worked also by run the application as a standalone .exe file.
With PyInstaller it worked even without AV alarm.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论