pyinstaller one file --no-console does not work “Fatal Error”

一曲冷凌霜 提交于 2020-01-19 06:06:44

问题


I try 2 options with pyinstaller one with console and one without.

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:

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")

Here are the pyinstaller commands with the exact same code:

- With console window aka works:

pyinstaller -F -i favicon.ico Test.py

- Without the console Window fails

pyinstaller -F --noconsole -i favicon.ico Test.py

I get this error:

*"Failed to execute script error"*

I am not sure why.

Thanks


Thanks for your reply I looked in:

C:\Users\testuser\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\chrome\service.py

There was nothing for subprocess here.

I also checked:

C:\Users\testuer\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\common\service.py

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)

Recreated with pyinstaller:

pyinstaller -F --noconsole  -i favicon.ico Test.py

This created the exe however now the console window appeared....

Python program with selenium(webdriver) Don't Work as single and noconsole exe file (pyinstaller)


回答1:


after some search I found the full solution : Firstly go to -

C:\Python35\Lib\site-packages\selenium\webdriver\common\service.py

Change :

self.process = subprocess.Popen(cmd, env=self.env,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self.log_file, stderr=self.log_file)

To:

self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)

now simply build your app.py like this:

pyinstaller --noconsole --onefile  --noupx   Yourfile.py



回答2:


I hope this helps someone:

C:\Users*/user_name/*\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\selenium\webdriver\common

Add import and change in "def start":

from win32process import CREATE_NO_WINDOW

    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, creationflags=CREATE_NO_WINDOW)
    except TypeError:
        raise

if error, check pywin32: pip install pywin32



来源:https://stackoverflow.com/questions/46639052/pyinstaller-one-file-no-console-does-not-work-fatal-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!