Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带有selenium(webdriver)Don';t作为单个和noconsole exe文件(pyinstaller)工作_Python_Selenium_Webdriver_Pyinstaller - Fatal编程技术网

Python 带有selenium(webdriver)Don';t作为单个和noconsole exe文件(pyinstaller)工作

Python 带有selenium(webdriver)Don';t作为单个和noconsole exe文件(pyinstaller)工作,python,selenium,webdriver,pyinstaller,Python,Selenium,Webdriver,Pyinstaller,以下是我的python代码: ## t.py ## from tkinter import messagebox from tkinter import * from selenium import webdriver def clicked(): iedriver = "C:\\Program Files\\Internet Explorer\\IEDriverServer.exe" try: driver=webdriver.Ie(iedr

以下是我的python代码:

## t.py ##

from tkinter import messagebox
from tkinter import *
from selenium import webdriver

def clicked():
    iedriver = "C:\\Program Files\\Internet Explorer\\IEDriverServer.exe"
    try:        
        driver=webdriver.Ie(iedriver)        
    except Exception as e:        
        messagebox.showerror("Error",e)
    driver.get('www.baidu.com')  
Top=Tk()
Button(Top,text='Click Me',command=clicked).pack()
Top.mainloop()
这很好,但当我使用PyInstaller(t.spec)将其转换为单个.exe文件时:

单击按钮运行时将提示以下错误:


当我在spec文件中将选项“console=0”更改为“console=1”时,点击按钮即可运行IE。知道当设置了“console=0”时为什么IE不能运行吗?

我想我通过修改selenium包中的服务类解决了这个问题。我不确定这是否是selenium(2.47.3)的错误。当调用
subprocess.Popen
函数时,原始代码仅重定向
stdout
stderr
,而不是
stdin

我修改了以下代码:

self.process = subprocess.Popen(cmd,
                stdout=PIPE, stderr=PIPE)
致:


然后问题就消失了。

在运行PATH环境变量之前,您是否尝试过在PATH环境变量上添加
C:\\Program Files\\Internet Explorer
?是的,我的路径如下,但仍然无法解决此问题:PATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windo ws\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Python34;“C:\Pro-gram Files\Internet Explorer”在您的上一条评论中,“Pro”和“gram”之间有一个空格,这是您评论中的一个打字错误吗?是的,这是我的错误,但在我的系统路径中是正确的,这无法解决问题。新方法如下:
self.process = subprocess.Popen(cmd,
                stdout=PIPE, stderr=PIPE)
self.process = subprocess.Popen(cmd, stdin=PIPE,
                stdout=PIPE, stderr=PIPE)