0
以下Python腳本運行的罰款:cx_freeze不能導入JSONDecoder
#!/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
你需要包含模塊'encodings.hex_codec'。我已經打開[問題](https://bitbucket.org/anthony_tuininga/cx_freeze/issue/17/hooks-python-2-json-simplejson-dynamically)以自動完成此操作。 –
如果你把它放在「答案」中,那麼我會接受它。它現在運行。它只會給出這個錯誤:異常KeyError:KeyError(140052806182656),在忽略 –
我只是試圖複製這個,我不能。我不確定你的Python安裝和我的版本有什麼不同(我在Ubuntu 12.10上使用2.6.8和2.7.3)。 –