在已编译的py2exe app selenium中缺少文件

时间:2014-09-03 21:21:38

标签: python selenium py2exe

我正在努力让我的Selenium应用程序正常运行。它编译了所有内容,但是当我打开应用程序时它会给我这个:

C:\Python34\dist>browse.exe
Traceback (most recent call last):
File "browse.py", line 9, in <module>
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 43, in __init__
self.profile = FirefoxProfile()
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile
.py", line 64, in __init__
WEBDRIVER_PREFERENCES)) as default_prefs:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Python34\\dist\\lib
rary.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.json'

我使用py2exe进行捆绑,将Firefox作为浏览器驱动程序。

Setup.py:

from distutils.core import setup
import py2exe

setup(
console=['browse.py'],
options={
        "py2exe":{
                "skip_archive": True,
                "unbuffered": True,
                "optimize": 2
        }
}
)

2 个答案:

答案 0 :(得分:3)

检查原始答案: Python - Trouble in building executable

您必须手动将webdriver.xpi和webdriver_prefs.json从C:\ Python27 \ Lib \ site-packages \ selenium \ webdriver \ firefox复制到dist \ selenium \ webdriver \ firefox

答案 1 :(得分:1)

这有效:编辑firefox_profile.py:WEBDRIVER_EXT,WEBDRIVER_PREFERENCES:

如果getattr(sys,&#39;冻结&#39;,False):WEBDRIVER_EXT = os.path.join(os.path.dirname(sys.executable),&#34; webdriver.xpi&#34;) WEBDRIVER_PREFERENCES = os.path.join(os.path.dirname(sys.executable),&#34; webdriver_prefs.json&#34;) elif文件:WEBDRIVER_EXT = os.path.join(os.path.dirname(file),&#34; webdriver.xpi&#34;)WEBDRIVER_PREFERENCES = os.path.join(os.path.dirname(file),&# 34; webdriver_prefs.json&#34)

转到行#34;打开(....&#34;并替换为&#34;打开(WEBDRIVER_PREFERENCES)作为default_prefs&#34;