【问题标题】:Python 2.7 Spynner cx_FreezePython 2.7 Spynner cx_Freeze
【发布时间】:2013-06-14 07:11:16
【问题描述】:

我在将 Python 2.7 超级简单脚本冻结为独立应用程序时遇到了问题。

我使用 Spynner 完全没有问题,但是当我尝试冻结我的超级简单脚本时:

from spynner import *

在 CMD 中打开“test.exe”时出现以下错误:

C:\Python27\Scripts\MY\build\exe.win32-2.7>test.exe
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", li
    exec code in m.__dict__
  File "test.py", line 1, in <module>
  File "C:\Python27\lib\site-packages\spynner-2.4-py2.7.egg\spynner\__init_
    from browser import *
  File "C:\Python27\lib\site-packages\spynner-2.4-py2.7.egg\spynner\browser
    class Browser(object):
  File "C:\Python27\lib\site-packages\spynner-2.4-py2.7.egg\spynner\browser
    pkg_resources.resource_filename('spynner', 'javascript'),
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 882, in resource
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 1344, in get_res
NotImplementedError: resource_filename() only supported for .egg, not .zip

提前感谢您的任何想法。

【问题讨论】:

  • 这里还有一个截图,描述了我上面提到的问题。 img96.imageshack.us/img96/9018/vfrs.png
  • spynner 正在使用一种存储数据文件的方式,这种方式在冻结为 zip 文件时无法使用。您必须对其进行修补以在您指定的位置查找其 javascript 文件。

标签: python-2.7 cx-freeze spynner


【解决方案1】:

我有同样的问题,我解决了,分享我的解决方案,
我更改 spynner 模块源代码“browser.py”第 77 行

class Browser(object):
    """
    Stateful programmatic web browser class based upon QtWebKit.
    """
    errorCode = None
    errorMessage = None
    if hasattr(sys, "frozen"):
        Handle_Frozen_Location = os.path.join(os.path.dirname(sys.executable), 'javascript')
    else:
        Handle_Frozen_Location = pkg_resources.resource_filename('spynner', 'javascript')
    _javascript_directories = [Handle_Frozen_Location, ]
    _jquery = 'jquery-1.5.2.js'
    _jquery_simulate = 'jquery.simulate.js'
#.....# all the same

比 从 C:\Python27\Lib\site-packages\spynner-2.15-py2.7.egg\spynner 复制 javascript 文件夹
(上面是 Windows 路径...)
到您的构建文件夹中,例如 c:\somewhere\build\exe.win32-2.7
希望能解决您的问题...

【讨论】:

    猜你喜欢
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多