I wrote an application using selenium firefox webdriver and compiled it with cx_Freeze. When I start my application I get an error:
Traceback (most recent call last):
File "c:\111\ui\__init__.py", line 27, in login
self.browser = self.webdriver.Firefox()
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 47, in __init__
self.profile = FirefoxProfile()
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 63, in __init__
WEBDRIVER_PREFERENCES)) as default_prefs:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\111\\build\\exe.win32-3.4\\library.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
But my library.zip actually contains webdriver_prefs.json and webdriver.xpi. I use next setup.py file to add it:
import sys
from cx_Freeze import setup, Executable
base= 'C:\\Python34\\Lib\\site-packages\\selenium\\webdriver'
includes = [
('%s\\firefox\\webdriver.xpi' %(base), 'selenium/webdriver/firefox/webdriver.xpi'),
('%s\\firefox\\webdriver_prefs.json '%(base), 'selenium/webdriver/firefox/webdriver_prefs.json')
]
build_exe_options = {
"packages": ["os"],
"excludes": ["tkinter"],
"zip_includes": includes,
}
setup(
name = "lala",
version = "0.1",
description = "lalala",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)],
)
Shoud I somehow register this files for my executable? And why traceback prints filepaths with two ways (one backslash and two backslashes)?
Finally I wasn't able to solve problem with cx_Freeze
but then I tried PyInstaller
and it works like a charm! It supports Python3 already by the way. I used that command:
c:\Python34\Scripts\pyinstaller.exe -p C:\Python34\Lib\site-packages -F app.py