Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

python - Py2exe isn't copying webdriver_prefs.json into builds

I'm using py2exe to compile a Python 2.7 script that uses Selenium 2.39.0 to open up Firefox windows and carry out some routines. In the past, I've been able to compile the code without any issue. Today though, after updating from Selenium 2.35 to 2.39, I'm running into trouble. When I try to run the .exe generated by the compiled code, I get the following error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "Tkinter.pyo", line 1410, in __call__
  File "literatureonlineapi2.5.5.py", line 321, in startapi
  File "seleniumwebdriverfirefoxwebdriver.pyo", line 43, in __init__
  File "seleniumwebdriverfirefoxfirefox_profile.pyo", line 58, in __init__
IOError: [Errno 2] No such file or directory: 'C:\Text\Professional\Digital H
umanities\Programming Languages\Python\Query Literature Online\LION 1.0\2.5
\2.5.5\dist\.\selenium\webdriver\firefox\webdriver_prefs.json'
Here we go!
Exception in Tkinter callback
Traceback (most recent call last):
  File "Tkinter.pyo", line 1410, in __call__
  File "literatureonlineapi2.5.5.py", line 321, in startapi
  File "seleniumwebdriverfirefoxwebdriver.pyo", line 43, in __init__
  File "seleniumwebdriverfirefoxfirefox_profile.pyo", line 58, in __init__
IOError: [Errno 2] No such file or directory: 'C:\Text\Professional\Digital H
umanities\Programming Languages\Python\Query Literature Online\LION 1.0\2.5
\2.5.5\dist\.\selenium\webdriver\firefox\webdriver_prefs.json'

(This error does not appear when I run the uncompiled code.)

I came across a google code page that led me to believe newer versions of Selenium have had trouble with this missing webdriver_prefs.json file, but that didn't help me sort out the problem.

Does anyone know how I might manually provide the missing file? I would be grateful for any help others can offer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found a solution, and thought I would post it in case others have a similar problem. I found the missing webdriver_prefs.json file tucked away in

C:Python27Libsite-packagesselenium-2.39.0-py2.7.eggseleniumwebdriverfirefox

After I had navigated to that directory, I grabbed the webdriver_prefs.json file and the webdriver.xpi file. I then copied both of those files into

distseleniumwebdriverfirefox

created by py2exe, and was able to run the compiled code as expected. God save the queen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...