牛爱特卡nuitka
win7 64位系统 sp1
python 版本 3.6.7 64位
使用了虚拟python 环境 在虚拟python 环境下,也可以使用nuitka
使用python3.8.2 64位 nuitka打包有点问题,不知道具体原因
有pyqt打包问题:可以加 QQ: 3200749719 ,pyinstaller 和 nuitka 都可以
参考网页
Python打包exe的王炸-Nuitka
https://zhuanlan.zhihu.com/p/133303836
https://github.com/Nuitka/Nuitka
https://github.com/PowerShell/PowerShell#get-powershell
Nuitka之乾坤大挪移-让天下的Python都可以打包(多文件,多目录打包)
https://zhuanlan.zhihu.com/p/137785388
虚拟环境
在c盘创建目录:
C:\python367_64
双击 python-3.6.7-amd64.exe
自定义安装,自定目录位置为:C:\python367_64\
安装好 virtualenvwrapper-win
pip install virtualenvwrapper-win
workon
mkvirtualenv -p C:\Python367_32\python.exe py367_32_etc_consume
mkvirtualenv -p C:/python367_64/python.exe py367_64_etc_add_oil
workon py367_64_etc_add_oil
deactivate
在虚拟环境中
pip install PyQt5-tools
pip install pyqt5
pip install PyQtChart
pip install PyQtWebEngine
pip install QScintilla
安装minGW
虚拟环境 python 3.6.7 64位
设置环境变量
path
C:\MinGW64\mingw64\bin
path 中同时有 C:\python367_64 和 C:\python367_64\Scripts
4.安装 Nuitka
在虚拟环境中
pip install nuitka
或者安装最新版本(根据使用经验发现新版本修复问题多,兼容性更好)
pip install -U “https://github.com/Nuitka/Nuitka/archive/develop.zip”
编译测试1:
F:\pyqt\nuitka\hello
hello.py
内容为:
def talk(message):
return "Talk " + message
def main():
print( talk("Hello World"))
if __name__ == "__main__":
main()
命令为:
python -m nuitka --standalone --mingw64 hello.py
编译测试2:
F:\pyqt\nuitka\draw>
qt04_drawPen.py
qt04_drawPen.py
内容为:
# -*- coding: utf-8 -*-
"""
【简介】
绘图中QPen 的例子 ,绘制使用不同样式的6条线
"""
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt
class Drawing(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 280, 270)
self.setWindowTitle('钢笔样式例子')
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.drawLines(qp)
qp.end()
def drawLines(self, qp):
pen = QPen(Qt.black, 2, Qt.SolidLine)
qp.setPen(pen)
qp.drawLine(20, 40, 250, 40)
pen.setStyle(Qt.DashLine)
qp.setPen(pen)
qp.drawLine(20, 80, 250, 80)
pen.setStyle(Qt.DashDotLine)
qp.setPen(pen)
qp.drawLine(20, 120, 250, 120)
pen.setStyle(Qt.DotLine)
qp.setPen(pen)
qp.drawLine(20, 160, 250, 160)
pen.setStyle(Qt.DashDotDotLine)
qp.setPen(pen)
qp.drawLine(20, 200, 250, 200)
pen.setStyle(Qt.CustomDashLine)
pen.setDashPattern([1, 4, 5, 4])
qp.setPen(pen)
qp.drawLine(20, 240, 250, 240)
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = Drawing()
demo.show()
sys.exit(app.exec_())
命令为:
nuitka --mingw64 --standalone --show-progress --show-memory --plugin-enable=qt-plugins --plugin-enable=pylint-warnings --recurse-all --recurse-not-to=numpy,jinja2 --output-dir=out qt04_drawPen.py
实在搞不定,就在一个 干净的 环境中测试一下
不要有 python 多版本,不要python 虚拟环境等等.
在一个win7 64位的干净环境中 ,设置了python 和 mingw的环境变量.
可以编译成功,编译后的 不是一个 exe ,而是 exe 和他依赖的库的 ,
也就是 pyinstaller -D的那种效果.
把代码给别人 也是 需要把文件夹给别人
win7 下 不需要安装 powercmd.exe
遇到问题
ModuleNotFoundError: No module named ‘help_ui_qrc_rc’
这个文件是 我自己定义的
在pyinstaller 中打包 也是找不到,需要通过 -p 参数 制定他的目录
多文件 多目录打包
参考操作视频:
Nuitka之乾坤大挪移-让天下的Python都可以打包
https://zhuanlan.zhihu.com/p/137785388
看一下 里面的视频 :nuitka打包python成exe
挺好的
参考实例工程:
F:\pyqt\pyqt5_code_collection_jack\py_nuitka\multi_window_app
nuitka --standalone --mingw64 --show-memory --show-progress --nofollow-imports --plugin-enable=qt-plugins --follow-import-to=Help --follow-import-to=App --output-dir=o main.py
tree /F
main.py 调用 app.py ,app.py调用 Help.help_win.py
main.py 是主程序
OK是需要 手动复制到 生成的dist 目录下面的内容
同样的这个工程,使用下面的方法,也可以完成 打包,并正常运行:
nuitka --mingw64 --windows-disable-console --standalone --show-progress --show-memory --plugin-enable=qt-plugins --plugin-enable=pylint-warnings --recurse-all --recurse-not-to=numpy,jinja2 --output-dir=out main.py
多看一下 知乎的那个文档
有的库,有必要编译为c/C++的形式,有的 没必要