首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在cython中编译pyqt5和python代码

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

Stack Overflow用户
提问于 2019-06-14 10:42:16
回答 1查看 2.4K关注 0票数 2

用python3用pyqt5编译我的项目有可能吗?

我创建了一个具有以下内容的compyle.py文件:

代码语言:javascript
复制
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
)

我用这个注释运行这个文件,根据

代码语言:javascript
复制
python3 compile.py build_ext --inplace

但我发现了一个错误:

代码语言:javascript
复制
$ 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模块吗?我怎么能这么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-14 11:05:22

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

代码语言:javascript
复制
from PyQt5.QtWidgets import QApplication
from MainWindow import MainWindowApp

app = QApplication(sys.argv)
mainWindow = MainWindowApp()
sys.exit(app.exec_()) # <---
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56596517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档