Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

python - pyinstaller one file --no-console does not work "Fatal Error"

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:Seleniumchromedriver_win32chromedriver.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:UsersestuserAppDataLocalProgramsPythonPython35Libsite-packagesseleniumwebdriverchromeservice.py

There was nothing for subprocess here.

I also checked:

C:UsersestuerAppDataLocalProgramsPythonPython35Libsite-packagesseleniumwebdrivercommonservice.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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

C:Python35Libsite-packagesseleniumwebdrivercommonservice.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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...