简体   繁体   English

Pyinstaller Python3 Windows10 - App不会从.bat脚本启动

[英]Pyinstaller Python3 Windows10 - App will not start from .bat script

Using Python3 and Pyinstaller on Windows 10... I created an app that runs fine when double clicking on it or when running it directly from the command line. 在Windows 10上使用Python3和Pyinstaller ...我创建了一个可以在双击它或直接从命令行运行时运行良好的应用程序。 However, it only works with the command line from inside of the working directory (its home directory). 但是,它仅适用于工作目录(其主目录)内部的命令行。 I want to use Windows scheduler to launch the app periodically. 我想使用Windows调度程序定期启动应用程序。 When the time came that it was supposed to launch, The CMD window briefly flashed and the program quit. 当它应该启动时,CMD窗口会短暂闪烁并且程序退出。 So I ran it from the terminal using c:\\mydir\\my.exe 所以我使用c:\\mydir\\my.exe从终端运行它

I got the following traceback: 我得到了以下回溯:

Traceback (most recent call last):
  File "My.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "email2.py", line 12, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'pic.jpeg'
[10188] Failed to execute script my.exe

I checked. 我检查了。 The pic.jpeg file is still there. pic.jpeg文件仍然存在。

Just for a workaround I created a file called start.bat and placed it inside the working directory. 只是为了解决方法,我创建了一个名为start.bat的文件并将其放在工作目录中。 All I did was call the program with My.exe . 我所做的就是用My.exe调用该程序。 Again it runs fine from inside of the directory but not from outside. 它再次从目录内部运行良好,但不从外部运行。

Bottom line I just want to schedule the program to run automatically. 底线我只想安排程序自动运行。

You should include pic.jpeg as part of your my.exe bundle. 您应该将pic.jpeg作为my.exe包的一部分包含pic.jpeg Try adding: 尝试添加:

datas=[('pix.jpeg', '.')],

under the Analysis part of your .spec file. .spec文件的Analysis部分下。 Also, make sure you are producing a onefile bundle. 另外,请确保生成onefile包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM