python的py文件打包成exe_将python项目.py文件打包成.exe文件
安裝pyinstaller包
pip3 install pyinstaller
如果不行
pip3 install pyinstaller -i https://pypi.doubanio.com/simple
準備一個你要打包的.py文件,cd到該文件路徑下,打開cmd
在命令行中輸入:
pyinstaller -F xxx.py
或者
pyinstaller.exe -F xxx.py
都是可以的
運行之后會多出兩個文件夾,dist和build,打包好的文件在dist文件夾內
已經生成exe文件,直接點擊運行,結果如下
xxx.py
# coding=utf-8
import turtle
import time
turtle.pensize(5)
turtle.pencolor("yellow")
turtle.fillcolor("red")
turtle.begin_fill()
for _ in range(5):
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
time.sleep(2)
turtle.penup()
turtle.goto(-150, -120)
turtle.color("violet")
turtle.write("Done", font=('Arial', 40, 'normal'))
turtle.mainloop()
我這里用到-F,生成單個可執行文件。
一些常用參數:
-D, --onedir Create a one-folder bundle containing an executable (default)
-F,?--onefile Create a one-file bundled executable.
-n?NAME,?--name?NAME? ?Name to assign to the bundled app and spec file (default: first script’s basename)
-p?DIR,?--paths?DIR? ??A path to search for imports (like using PYTHONPATH). Multiple paths are allowed, separated by ‘:’, or use this option multiple times
-w,?--windowed,?--noconsole
總結
以上是生活随笔為你收集整理的python的py文件打包成exe_将python项目.py文件打包成.exe文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssd内部是多个flash一起操作_一键
- 下一篇: python字典导入mongodb_Py