鱼C论坛

 找回密码
 立即注册
查看: 7107|回复: 5

求助鱼油们,selenium用pyinstaller打包EXE出现问题~~~~

[复制链接]
发表于 2017-12-13 18:32:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
工作环境:
WIN7,64
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
简单测试代码:
  1. # -*- coding: utf-8 -*-

  2. from selenium import webdriver
  3. import time
  4. from tkinter import *
  5. import win32com
  6. import os
  7. root = Tk()

  8. def test():
  9.     driver = webdriver.Chrome(executable_path='./chromedriver.exe')
  10.     driver.get('http://bbs.fishc.com/')
  11.     time.sleep(5)
  12.     driver.quit()

  13. Button(root,text='123',command=test).pack()
  14. mainloop()
复制代码

问题描述:
1,使用pyinstaller.exe -F -w,调用不了driver
2,使用pyinsraller.exe -F ,可以正常使用,但存在.py命令窗口,窗口内提示 ERROR:gl_surface_egl.cc(777) eglIntialize D3D11 failed with error EGL_NOT_INITIALIZED,trying next display type
3,使用pyinsraller.exe -D -w,可以正常使用,但存在chromedriver.exe,命令窗口,窗口提示如同第二种方法

想要隐藏命令窗口,鱼油这问题如何解决呢?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-12-14 13:25:19 | 显示全部楼层
找到解决方案了
原地址
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-16 15:06:02 | 显示全部楼层
Jackmok 发表于 2017-12-14 13:25
找到解决方案了
原地址

我之前打包也遇到这个问题,没有解决
你把你解决的方法链接回复一下我,我看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-16 18:35:03 | 显示全部楼层
gopythoner 发表于 2017-12-16 15:06
我之前打包也遇到这个问题,没有解决
你把你解决的方法链接回复一下我,我看看

我也是网上找到的方案,下面是转贴过来
修改代码   位于 D:\Python35\Lib\site-packages\selenium\webdriver\common\service.py
  1. def start(self):
  2.         """
  3.         Starts the Service.

  4.         :Exceptions:
  5.          - WebDriverException : Raised either when it can't start the service
  6.            or when it can't connect to the service
  7.         """
  8.         try:
  9.             cmd = [self.path]
  10.             cmd.extend(self.command_line_args())
  11.             if 'win32' in str(sys.platform).lower():   ### 这里判断是否是windows平台
  12.                 ###   在windows平台上就隐藏窗口

  13.                 startupinfo = subprocess.STARTUPINFO()
  14.                 startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
  15.                 startupinfo.wShowWindow = subprocess.SW_HIDE
  16.             else:
  17.                 startupinfo = None


  18.             self.process = subprocess.Popen(cmd, env=self.env,
  19.                                             close_fds=platform.system() != 'Windows',
  20.                                             stdout=self.log_file, stderr=self.log_file,startupinfo=startupinfo)   ### 启动驱动



  21.             self.PID = self.process.pid  ### 将cmd窗口的进程pid 保留   因为 窗口被隐藏了  所以在后续程序中必须考虑主控进程结束的时候必须结束掉 驱动cmd窗口进程
  22.         except TypeError:
  23.             raise
  24.         except OSError as err:
  25.             if err.errno == errno.ENOENT:
  26.                 raise WebDriverException(
  27.                     "'%s' executable needs to be in PATH. %s" % (
  28.                         os.path.basename(self.path), self.start_error_message)
  29.                 )
  30.             elif err.errno == errno.EACCES:
  31.                 raise WebDriverException(
  32.                     "'%s' executable may have wrong permissions. %s" % (
  33.                         os.path.basename(self.path), self.start_error_message)
  34.                 )
  35.             else:
  36.                 raise
  37.         except Exception as e:
  38.             raise WebDriverException(
  39.                 "The executable %s needs to be available in the path. %s\n%s" %
  40.                 (os.path.basename(self.path), self.start_error_message, str(e)))
  41.         count = 0
  42.         while True:
  43.             self.assert_process_still_running()
  44.             if self.is_connectable():
  45.                 break
  46.             count += 1
  47.             time.sleep(1)
  48.             if count == 30:
  49.                 raise WebDriverException("Can not connect to the Service %s" % self.path)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-2-24 14:35:11 | 显示全部楼层
看到啦!不知道是否对我的·有用!!!依然大赞!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-4 11:43:44 | 显示全部楼层
我遇到了相同的问题,用pyinstaller在win10打包可以运行,放在win7上就会报这个错误,而且涉及到点击操作就会直接退出。
我想问下你那个egl报错的问题是如何解决的,是直接修改service.py里面的start函数吗,我修改之后没有变化
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-26 12:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表