2

I am trying to get my Selenium app to work. It compiles everything, but when I open the app it gives me this:

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'

I'm using py2exe to bundle, and Firefox as my browser driver.

Setup.py:

from distutils.core import setup
import py2exe

setup(
console=['browse.py'],
options={
        "py2exe":{
                "skip_archive": True,
                "unbuffered": True,
                "optimize": 2
        }
}
)
Celeo
  • 5,583
  • 8
  • 39
  • 41
Shrekt
  • 195
  • 1
  • 4
  • 15

2 Answers2

3

Check the original answer: Python - Trouble in building executable

You have to manually copy both webdriver.xpi and webdriver_prefs.json from C:\Python27\Lib\site-packages\selenium\webdriver\firefox to dist\selenium\webdriver\firefox

Community
  • 1
  • 1
pppk520
  • 517
  • 4
  • 15
1

This worked: Edit firefox_profile.py: WEBDRIVER_EXT, WEBDRIVER_PREFERENCES:

if 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(file), "webdriver_prefs.json")

goto the line "with open(...." and replace with "with open(WEBDRIVER_PREFERENCES) as default_prefs"