如何在cython中编译pyqt5和python代码

如何在cython中编译pyqt5和python代码,python,python-3.x,pyqt,pyqt5,cython,Python,Python 3.x,Pyqt,Pyqt5,Cython,可以用python3和pyqt5以及cython编译我的项目吗 我创建了一个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("MainWin

可以用python3和pyqt5以及cython编译我的项目吗

我创建了一个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
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
模块?我该怎么做呢?

虽然python允许使用
app.exec()
,但cython更严格,解决方案是使用
app.exec()

从PyQt5.QtWidgets导入QApplication
从MainWindow导入MainWindowApp
app=QApplication(sys.argv)
mainWindow=MainWindowApp()

sys.exit(app.exec#())#我想这是因为Cython仍然默认将代码解释为Python2。我猜将语言级别设置为3也会起作用(因为
exec
将不再是一个语句)@DavidW它可能是,但正式的函数是app.exec_(),尽管如图所示,app.exec()也是允许的。IMHO使用exec_u3;()并避免兼容性problems@eyllanesc老兄编译后我怎么能运行这些文件@sayreskabir Cython不会生成一个可以自己执行的应用程序,而是生成一个必须导入的库。我建议你调查一下Cython是什么,它是做什么的,它的作用是什么,这样你就知道你必须做什么来执行你的应用程序
$ 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