简体   繁体   English

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

[英]How to compile pyqt5 and python code in cython

Is it possible to compile my project with python3 with pyqt5 with cython?是否可以用 python3 和 pyqt5 用 cython 编译我的项目?

I have created a compyle.py file with these content:我创建了一个包含以下内容的 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
)

and i run this file with this comment according this :我根据这个评论运行这个文件:

python3 compile.py build_ext --inplace

But i got this error:但我收到了这个错误:

$ 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

I think cython can compile PyQt5 module?我认为 cython 可以编译PyQt5模块吗? How could i do that?我怎么能那样做?

Although python tolerates using app.exec() , cython is stricter, the solution is to use app.exec_() :虽然 python 容忍使用 app.exec app.exec() ,但 cython 更严格,解决方案是使用app.exec_()

from PyQt5.QtWidgets import QApplication
from MainWindow import MainWindowApp

app = QApplication(sys.argv)
mainWindow = MainWindowApp()
sys.exit(app.exec_()) # <---

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM