cx_freeze无法导入JSONDecoder

时间:2013-01-10 09:00:42

标签: python json cx-freeze

以下python脚本运行良好:

#!/usr/bin/python
import simplejson

print str(simplejson.loads('{"a": "abc"}'))

冻结之后:

cxfreeze test.py --target-dir dist

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/cx_Freeze/initscripts/Console.py", line 29, in <module>
    exec code in m.__dict__
  File "test.py", line 3, in <module>
    import simplejson as json
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 111, in <module>
    from decoder import JSONDecoder, JSONDecodeError
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 29, in <module>
    NaN, PosInf, NegInf = _floatconstants()
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 21, in _floatconstants
    _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
LookupError: unknown encoding: hex

这没有用:

cxfreeze test.py --target-dir dist --include-modules simplejson

也没有从simplejson切换到json帮助。

当冻结simplejson部分时似乎没有错误:

P simplejson                /usr/lib/python2.7/dist-packages/simplejson/__init__.py
m simplejson._speedups      /usr/lib/python2.7/dist-packages/simplejson/_speedups.so
m simplejson.decoder        /usr/lib/python2.7/dist-packages/simplejson/decoder.py
m simplejson.encoder        /usr/lib/python2.7/dist-packages/simplejson/encoder.py
m simplejson.ordered_dict   /usr/lib/python2.7/dist-packages/simplejson/ordered_dict.py
m simplejson.scanner        /usr/lib/python2.7/dist-packages/simplejson/scanner.py

2 个答案:

答案 0 :(得分:1)

(转发回答)

您需要包含模块encodings.hex_codec。我已经打开an issue以自动完成此操作。

答案 1 :(得分:0)

添加:

来自编码的

导入hex_codec

并在使用freeze.py构建时添加 -m编码。 它适用于我。