2014-09-06 88 views
3

我有一個使用硒包的python程序,當使用pyinstaller創建一個exe文件時,它會正確創建exe文件。當試圖從這個程序打開Firefox,我得到了以下錯誤:找不到webdriverprefs.json - pyinstaller

 
IOError: [Errno 2] No such file or directory: 
'C:\\users\\mohamed\\Temp\\_MEI622\\selenium\\webdriver\\firefox\\webdriver_prefs.json' 

我發現這個解決方案,但它不爲我工作:

Py2exe isn't copying webdriver_prefs.json into builds

任何想法?

回答

3

我發現一個相同的解決方案, 凍結腳本exe文件不使用--onefile,而是使用--onedir,它會爲所有文件生成一個文件夾,然後複製硒文件夾路徑c:\ python27 \ lib \ site-packages \ selenium添加到您的應用程序文件夾並且它可以正常工作

-1

根據我的經驗,pyinstaller在創建可執行文件時總會產生混亂。我建議你改用py2exe

+0

這不回答問題,主要是基於意見。如果有人來這裏尋找如何解決這個PyInstaller,這可能不會幫助他們非常多。 – 2017-09-04 10:17:59

2

只需在您的.spec文件中包含這些(.json & .xpi)文件作爲任意文件。

這裏是爲我工作(您可能需要更改路徑):

needed_selenium_files = [(r'selenium\webdriver\firefox\webdriver_prefs.json', 
          r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver_prefs.json', 
          'DATA'), 
         (r'selenium\webdriver\firefox\webdriver.xpi',   
          r'C:\Anaconda\Lib\site-packages\selenium\webdriver\firefox\webdriver.xpi', 
          'DATA')] 

,稍後:

coll = COLLECT(exe, a.binaries, needed_selenium_files, ...) 

閱讀更多關於PyInstaller手冊: http://pythonhosted.org/PyInstaller/#toc-class-table-of-contentshttp://pythonhosted.org/PyInstaller/#adding-files-to-the-bundle

+0

這爲我工作,那麼你應該運行pyinstaller filename.spec – HabibKazemi 2015-09-30 15:42:33