Intento 2 opciones con pyinstaller, uno con consola y otro sin.
Estoy usando Windows 10, Python 3.5.4, Windows Chrome Driver 2.33 y Selnium 3.6.0 y Pyinstaller 3.3.
El que no tiene consola falla:
Aquí está el código para 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")
Aquí están los comandos de pyinstaller con el mismo código exacto:
– Con la ventana de la consola alias funciona:
pyinstaller -F -i favicon.ico Test.py
– Sin la consola la ventana falla
pyinstaller -F --noconsole -i favicon.ico Test.py
Me sale este error:
*"Failed to execute script error"*
No estoy seguro por qué.
Gracias
Gracias por su respuesta miré en:
C:\Users\testuser\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\chrome\service.py
No había nada para el subproceso aquí.
También he comprobado:
C:\Users\testuer\AppData\Local\Programs\Python\Python35\Lib\site-packages\selenium\webdriver\common\service.py
En la línea 70 agregué en la entrada para stdin = self.log_file ya que faltaba
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)
Recreado con pyinstaller:
pyinstaller -F --noconsole -i favicon.ico Test.py
Esto creó el exe sin embargo ahora apareció la ventana de la consola …
Progtwig Python con selenium (webdriver) No funciona como un archivo exe único y noconsole (pyinstaller)
Después de algunas búsquedas encontré la solución completa: Primero, vaya a
C:\Python35\Lib\site-packages\selenium\webdriver\common\service.py
Cambio :
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file)
A:
self.process = subprocess.Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=False, creationflags=0x08000000)
ahora simplemente construye tu app.py de esta manera:
pyinstaller --noconsole --onefile --noupx Yourfile.py
Espero que esto ayude a alguien:
C: \ Users * / nombre_usuario / * \ AppData \ Local \ Programs \ Python \ Python36-32 \ Lib \ site-packages \ selenium \ webdriver \ common
Agregue la importación y el cambio en “def start”:
desde 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
si hay un error, verifique pywin32: pip install pywin32