cx_freeze:可执行的回溯错误

时间:2015-08-31 22:26:49

标签: python python-3.x cx-freeze

出于某种原因,我在运行可执行文件时遇到此错误:

---------------------------
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "splinter1.py", line 8, in <module>
  File "C:\Python34\lib\splinter\browser.py", line 63, in Browser
    return driver(*args, **kwargs)
  File "C:\Python34\lib\splinter\driver\webdriver\firefox.py", line 23, in __init__
    firefox_profile = FirefoxProfile(profile)
  File "C:\Python34\lib\selenium\webdriver\firefox\firefox_profile.py", line 63, in __init__
    WEBDRIVER_PREFERENCES)) as default_prefs:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Admin\\Desktop\\exe.win32-3.4\\library.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.json'

---------------------------
OK   
---------------------------

这是真的,cx_freeze在原始版本中遗漏了webdriver_prefs.json,但我手动将其粘贴到library.zip\selenium\webdriver\firefox内,但我仍然收到错误。

这是我的设置文件:

import sys
from cx_Freeze import setup, Executable

exe=Executable(
     script="splinter1.py",
     base="Win32Gui",
     icon="icon.ico"
     )
includefiles=[]
includes=[]
excludes=[]
packages=[]
setup(

     version = "1.0",
     description = "No Description",
     author = "Name",
     name = "Bot search",
     options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
     executables = [exe]
     )

这是我的原始剧本:

from splinter import Browser
import contextlib
from selenium.webdriver import Remote
from selenium.webdriver.support import wait
from selenium.webdriver.support.expected_conditions import staleness_of
import time

browser = Browser('firefox')

CurrentR = 12345678

browser.visit('somewebsite')

browser.fill("field1","")
browser.fill("field2","")

browser.fill("field3",CurrentR)

#Find submit button and click
browser.find_by_id('btnSubmit').first.click()

#Wait for new page to load
class MyRemote(Remote):
    @contextlib.contextmanager
    def wait_for_page_load(self, timeout=30):
        old_page = self.find_element_by_tag_name('html')
        yield
        wait(self, timeout).until(staleness_of(old_page))

print('finished')

if browser.is_text_present('No Records Selected'):
    print("No records selected")
else:
    print("Some records exist")


time.sleep(120)

1 个答案:

答案 0 :(得分:0)

@Thomas K给出了正确答案。我在Python中的selenium目录中复制了整个Lib文件夹,并将其粘贴到我的.exe所在的同一目录中。