用python3用pyqt5编译我的项目有可能吗?
我创建了一个具有以下内容的compyle.py文件:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
Extension("Main", ["Main.py"]),
Extension("MainWindow", ["MainWindow.py"]),
Extension("CopyDialog", ["CopyDialog.py"]),
Extension("CopyDebugThread", ["CopyDebugThread.py"])
]
setup(
name = 'My Program Name',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)我用这个注释运行这个文件,根据这
python3 compile.py build_ext --inplace但我发现了一个错误:
$ python3 compile.py build_ext --inplace
running build_ext
cythoning Main.py to Main.c
/home/groot/.local/lib/python3.6/site-packages/Cython/Compiler/Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/groot/PythonProject/ConfigServer/Main.py
tree = Parsing.p_module(s, pxd, full_module_name)
Error compiling Cython file:
------------------------------------------------------------
...
from PyQt5.QtWidgets import QApplication
from MainWindow import MainWindowApp
app = QApplication(sys.argv)
mainWindow = MainWindowApp()
sys.exit(app.exec()) ^
------------------------------------------------------------
Main.py:7:13: Expected an identifier
building 'Main' extension
creating build
creating build/temp.linux-x86_64-3.6
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -c Main.c -o build/temp.linux-x86_64-3.6/Main.o
Main.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
#error Do not use this file, it is the result of a failed Cython compilation.
^~~~~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1我认为cython可以编译PyQt5模块吗?我怎么能这么做?
发布于 2019-06-14 11:05:22
虽然python允许使用app.exec(),但cython更严格,解决方案是使用app.exec_()。
from PyQt5.QtWidgets import QApplication
from MainWindow import MainWindowApp
app = QApplication(sys.argv)
mainWindow = MainWindowApp()
sys.exit(app.exec_()) # <---https://stackoverflow.com/questions/56596517
复制相似问题