2014-09-03 82 views
2

我想讓我的Selenium應用程序工作。它編譯一切,但是當我打開應用程序它給了我這樣的:編譯好的py2exe應用程序硒文件丟失

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 
     } 
} 
) 
+0

你找到你的答案因爲我也有同樣的錯誤。並且你在下面選擇的答案也沒有幫助 – 2015-05-29 14:20:53

回答

3

檢查原來的答案: Python - Trouble in building executable

您必須手動將複製下,兩個webdriver.xpi和webdriver_prefs.json:\ Python27 \ LIB \站點包\硒\ webdriver的\ Firefox來DIST \硒\ webdriver的\火狐

1

這工作:編輯firefox_profile.py:WEBDRIVER_EXT,WEBDRIVER_PREFERENCES:

如果getattr(sys,'frozen',False):WEBDRIVER_EXT = os.path.join(os.path.dirname(sys.executable),「webdriver.xpi」)WEBDRIVER_PREFERENCES = os.path.join(os.path .dirname(sys.executable),「webdriver_prefs.json」) elif file:WEBDRIVER_EXT = os.path.join(os.path.dirname(file),「webdriver.xpi」)WEBDRIVER_PREFERENCES = os.path.join(os .path.dirname(文件), 「webdriver_prefs.json」)

轉到行 「打開(....」 並替換爲 「開放(WEBDRIVER_PREFERENCES)爲default_prefs」

+0

嗨。你到底在哪裏編輯這個文件?哪個文件夾? – dsauce 2017-11-03 11:05:52

相關問題