【问题标题】:Error when compiling PyQt4 with Pyinstaller使用 Pyinstaller 编译 PyQt4 时出错
【发布时间】:2012-02-19 15:31:50
【问题描述】:

过去,我使用 pycompiler(或“pyinstaller”)将我的程序编译为使用 PyQt4 框架的可执行代码,仅仅是因为 py2exe。
我最近换了电脑,还没有设法在上面编译我的 PyQt4 程序!

在这台电脑上,我设置了一个环境变量 %pycompile% ,其中包含 pyinstaller.py 文件的目录。

这是我插入 cmd.exe 的代码,它与 Python 代码 NOT IMPORT PYQT4 一起使用。

python %pycompile% --noconsole myscript.pyw

但是,当我尝试编译基于 PyQt4 的程序时,在尝试编译 PyQt4 程序时,我得到一个源自 pyinstaller.py 导入的 python 文件内部的语法错误(根据我的解释)。 "exec_ = 执行"

E:\ChemCalc ULTIMATE\ChemCalc ULTIMATE>python %pycompile% Penny.pyw
I: skip Configure.py, use existing config C:\Python27\PyCompile\config.dat
wrote E:\ChemCalc ULTIMATE\ChemCalc ULTIMATE\Penny.spec
I: Dependent assemblies of C:\Python27\python.exe:
I: x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
checking Analysis
building Analysis because outAnalysis0.toc non existent
running Analysis outAnalysis0.toc
Analyzing: C:\Python27\PyCompile\support\_mountzlib.py
Analyzing: C:\Python27\PyCompile\support\useUnicode.py
Analyzing: Penny.pyw
Syntax error in exec_py3.py
('invalid syntax', ('exec_py3.py', 1, 12, 'exec_ = exec\n'))
Traceback (most recent call last):
  File "C:\Python27\PyCompile\pyinstaller.py", line 187, in <module>
    main(parser)
  File "C:\Python27\PyCompile\pyinstaller.py", line 76, in main
    run_build(opts, args, spec_file)
  File "C:\Python27\PyCompile\pyinstaller.py", line 52, in run_build
    Build.main(spec_file, configfilename=opts.configfile)
  File "C:\Python27\PyCompile\Build.py", line 1472, in main
    build(specfile)
  File "C:\Python27\PyCompile\Build.py", line 1429, in build
    execfile(spec)
  File "E:\ChemCalc ULTIMATE\ChemCalc ULTIMATE\Penny.spec", line 3, in <module>
    pathex=['E:\\ChemCalc ULTIMATE\\ChemCalc ULTIMATE'])
  File "C:\Python27\PyCompile\Build.py", line 347, in __init__
    self.__postinit__()
  File "C:\Python27\PyCompile\Build.py", line 298, in __postinit__
    self.assemble()
  File "C:\Python27\PyCompile\Build.py", line 416, in assemble
    analyzer.analyze_script(script)
  File "C:\Python27\PyCompile\mf.py", line 572, in analyze_script
    return self.analyze_r('__main__')
  File "C:\Python27\PyCompile\mf.py", line 466, in analyze_r
    newnms = self.analyze_one(name, nm, imptyp, level)
  File "C:\Python27\PyCompile\mf.py", line 525, in analyze_one
    mod = self.doimport(nm, ctx, fqname)
  File "C:\Python27\PyCompile\mf.py", line 587, in doimport
    mod = parent.doimport(nm)
  File "C:\Python27\PyCompile\mf.py", line 761, in doimport
    mod = self.subimporter.getmod(nm)
  File "C:\Python27\PyCompile\mf.py", line 355, in getmod
    mod = owner.getmod(nm)
  File "C:\Python27\PyCompile\mf.py", line 117, in getmod
    co = compile(string.replace(stuff, "\r\n", "\n"), py[0], 'exec')
  File "exec_py3.py", line 1
    exec_ = exec
               ^
SyntaxError: invalid syntax

我正在使用与旧计算机上相同的 pycompile 版本 (216)。它们都运行 32 位 Windows 和 32 位 python 2.7.2。

需要所有帮助!
(我吓坏了我的 MASSIVE 编程项目无法编译!)

我已经阅读了很多关于 PyQt 的 pyinstaller 错误的 Stack 问题,但不是我的特定错误!

谢谢!

我的代码以:

开头
import sys
import getpass
import hmac
import random
import shutil
from PyQt4 import QtGui, QtCore
from RegMenu import Ui_RegristrationMenu
from ChemWindow import Ui_ChemWindow
from ReactionClass import ReactionElement
from StoichUnitSelectionClass import Ui_StoichUnitSelection
from VisualTool import Ui_Aesthetics_Tool
import decimal  
import sympy  
import math

并以:

结尾
sys.exit(ApplicationRun.exec_())

python 2.7.2(32 位)
pycompile 构建 (216)
PyQt4 (4.5)
Windows 7(32 位)

【问题讨论】:

  • 也许你可以尝试一些替代方案?我正在使用cx_Freeze
  • 修复了它(pyinstaller),方法是使用链接到的紧张简单的 hack Avaris。谢谢!
  • 就在链接所说的地方。 C:\Python27\lib\site-packages\mpmath\libmp\exec_py3.py

标签: python compilation pyqt pyqt4 pyinstaller


【解决方案1】:

由 Avaris 的共享建议修复。
http://code.google.com/p/mpmath/issues/detail?id=204

【讨论】:

    【解决方案2】:

    似乎 pyinstaller 正在使用 Python 3,因为 exec_ = exec 仅在 Python 3 中是合法的,而且 exec_py3.py 在回溯中。 尝试为 pyinstaller 提供一个选项,告诉它使用 Python 2.7。

    【讨论】:

    • cmets 中提供了一个不优雅的方法。抱歉,忘记关闭此问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多