[英]Pyinstaller "FileNotFoundError: [Errno 2] No such file or directory:" when running app
I recently have packaged a python app using the pyinstaller --onefile
command.我最近使用pyinstaller --onefile
命令打包了一个 python 应用程序。 It succesfully makes a executable file that launches fine.它成功地制作了一个可以正常启动的可执行文件。 I can use pretty much almost all the functions in my script with no problem, except one.我几乎可以毫无问题地使用脚本中的所有函数,只有一个函数除外。 When I call a function of another python file (which is in my app folder), I get this error:当我调用另一个 python 文件(在我的应用程序文件夹中)的函数时,我收到此错误:
Traceback (most recent call last):
File "socketserver.py", line 647, in process_request_thread
File "socketserver.py", line 357, in finish_request
File "socketserver.py", line 717, in __init__
File "http/server.py", line 426, in handle
File "http/server.py", line 414, in handle_one_request
File "CaptchaHarvester/harvester/server/__init__.py", line 134, in do_GET
File "CaptchaHarvester/harvester/server/__init__.py", line 178, in handel_request
File "CaptchaHarvester/harvester/server/__init__.py", line 85, in _load_template
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/rl/rmr5s0ld22j0h_z15m90v0c80000gr/T/_MEIBVnHEv/harvester/server/templates/ga.chunk.html'
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 54955)
Traceback (most recent call last):
File "socketserver.py", line 647, in process_request_thread
File "socketserver.py", line 357, in finish_request
File "socketserver.py", line 717, in __init__
File "http/server.py", line 426, in handle
File "http/server.py", line 414, in handle_one_request
File "CaptchaHarvester/harvester/server/__init__.py", line 122, in do_GET
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/rl/rmr5s0ld22j0h_z15m90v0c80000gr/T/_MEIBVnHEv/harvester/server/icon.png'
The problem seems to be that pyinstaller cant properly find the files(icon.png and ga.hunk.html).问题似乎是 pyinstaller 无法正确找到文件(icon.png 和 ga.hunk.html)。 These files are in a folder that is in the same folder as my main.py file.这些文件位于与我的 main.py 文件位于同一文件夹中的文件夹中。 I was wondering how I can make pyinstaller find these files succesfully?我想知道如何让 pyinstaller 成功找到这些文件? I have tried to add to the datas class in the .spec file, but I still get the error.我试图添加到 .spec 文件中的 datas 类,但我仍然收到错误消息。 This is what that line looks like: datas=[('/Users/A/Desktop/ss/CaptchaHarvester/harvester/server/icon.png','/Users/A/Desktop/ss/CaptchaHarvester/harvester/server')],
Please let me know if I am doing something wrong or if yall have any ideas on how to resolve it.这是该行的样子: datas=[('/Users/A/Desktop/ss/CaptchaHarvester/harvester/server/icon.png','/Users/A/Desktop/ss/CaptchaHarvester/harvester/server')],
如果我做错了什么,或者你们对如何解决它有任何想法datas=[('/Users/A/Desktop/ss/CaptchaHarvester/harvester/server/icon.png','/Users/A/Desktop/ss/CaptchaHarvester/harvester/server')],
请告诉我。
I am on macosx catalina and python 3.7 if that is any help.如果有帮助,我在 macosx catalina 和 python 3.7 上。
Thanks!谢谢!
You can use arguments in command prompt to ensure the correct filesare found by pyinstaller;您可以在命令提示符中使用参数来确保 pyinstaller 找到正确的文件; --add-data "path_to_file:path_in_executable in directory"
an example would be --add-data "path_to_file:path_in_executable in directory"
一个例子是
pyinstaller --add-data "icon.png;." --onefile socketserver.py
here icon.png is in the same directoy of socketserver.py and is copied to the root directory of the executable (the .
signifies root directory)这里的icon.png和socketserver.py在同一个目录下,复制到可执行文件的根目录下( .
表示根目录)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.