pyinstaller 一个文件 --no-console 不起作用“致命错误"; [英] pyinstaller one file --no-console does not work "Fatal Error"
问题描述
我使用 pyinstaller 尝试了 2 个选项,一个带控制台,一个不带.
I try 2 options with pyinstaller one with console and one without.
我使用的是 Windows 10、Python 3.5.4、Windows Chrome 驱动程序 2.33 和 Selnium 3.6.0 以及 Pyinstaller 3.3.
I am using Windows 10, Python 3.5.4, Windows Chrome Driver 2.33 and Selnium 3.6.0 and Pyinstaller 3.3.
没有控制台失败:
The one without console fails:
这是 Test.py
Here is the code for Test.py
#!python3
from selenium import webdriver
# Chrome Proxy options and disable the Yellow Bar about Chrome being controlled by Automated Software.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-logging")
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--disable-default-apps")
chrome_options.add_argument("--disable-extensions")
# load google.com with the proxy settings and a logging path to a file
driver = webdriver.Chrome(r"D:\Selenium\chromedriver_win32\chromedriver.exe", chrome_options=chrome_options)
# maximise window
driver.maximize_window()
driver.get("https://www.google.com/mail")
以下是具有完全相同代码的 pyinstaller 命令:
Here are the pyinstaller commands with the exact same code:
- 使用控制台窗口也可以工作:
pyinstaller -F -i favicon.ico Test.py
- 没有控制台窗口失败
pyinstaller -F --noconsole -i favicon.ico Test.py
我收到此错误:
*"Failed to execute script error"*
我不知道为什么.
谢谢
感谢您的回复,我查看了:
Thanks for your reply I looked in:
C:\Users\testuser\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\chrome\service.py
这里没有子进程.
我也检查过:
C:\Users\testuer\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\common\service.py
在第 70 行,我添加了 stdin=self.log_file 的条目,因为它丢失了
On line 70 I added in the entry for stdin=self.log_file as it was missing
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdin=self.log_file, stdout=self.log_file, stderr=self.log_file)
使用 pyinstaller 重新创建:
Recreated with pyinstaller:
pyinstaller -F --noconsole -i favicon.ico Test.py
这创建了 exe 但是现在控制台窗口出现了....
This created the exe however now the console window appeared....
带有硒的 Python 程序(webdriver) 不要作为单个和 noconsole exe 文件 (pyinstaller) 工作
推荐答案
经过一番搜索,我找到了完整的解决方案:首先去-
after some search I found the full solution : Firstly go to -
C:\Python35\Lib\site-packages\selenium\webdriver\common\service.py
改变:
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file)
致:
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)
现在只需像这样构建您的 app.py:
now simply build your app.py like this:
pyinstaller --noconsole --onefile --noupx Yourfile.py
这篇关于pyinstaller 一个文件 --no-console 不起作用“致命错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!