码迷,mamicode.com
首页 > 编程语言 > 详细

将python项目.py文件打包成.exe文件

时间:2019-12-06 09:23:07      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:sim   main   imp   sep   pypi   com   info   tip   pytho   

安装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文件

标签:sim   main   imp   sep   pypi   com   info   tip   pytho   

原文地址:https://www.cnblogs.com/pfeiliu/p/11992983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!