分享

cxfreeze打包时出现“compile() expected string without null bytes”错误

 Tech-d 2012-11-30

cx_Freeze opens a compiled bytecode file, and scans for the magic number, '\xd1\xf2\r\n', but universal newline mode turns this into '\xd1\xf2\n', thus misidentifying the bytecode as Python source, which is then passed to compile, which crashes.

由网友PerryTatchett提供的解决方案:
在"/usr/lib/pymodules/python2.6/cx_Freeze/finder.py"中的58行左右,添加:
          module = self._AddModule(name)
          module.file = path
          module.parent = parent
+         # TOTAL HACK WORKAROUND BY PETER
+         if fp.name.endswith(".pyc"):
+             print "Peter's horrible hack is activiating, forcing", fp.name, "into binary mode, and as compiled Python."
+             type = imp.PY_COMPILED
+             # Next, switch out of universal newline mode in this crazy case.
+             fp.close()
+             fp = open(fp.name, "rb")
+         # END TOTAL HACK
          if type == imp.PY_SOURCE:
              module.code = compile(fp.read() + "\n", path, "exec")
          elif type == imp.PY_COMPILED:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多