用python打包exe應用程序及PyInstaller安裝方式
1、PyInstaller簡介
PyInstaller是一個跨平臺的Python應用打包工具,支持 Windows/Linux/MacOS三大主流平臺,能夠把 Python 腳本及其所在的 Python 解釋器打包成可執(zhí)行文件,從而允許最終用戶在無需安裝 Python 的情況下執(zhí)行應用程序。
PyInstaller 制作出來的執(zhí)行文件并不是跨平臺的,如果需要為不同平臺打包,就要在相應平臺上運行PyInstaller進行打包。
2、PyInstaller安裝
pip install Pyinstaller
有時候會安裝失敗?用以下方式安裝
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Pyinstaller
永久設置
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
3. 準備需要的文件

我們的tree文件夾放在c盤的
fac.ico?程序的圖標
tree.py?是python文件
4.使用Pyinstaller
使用默認Pyinstaller打包方式
打開cmd窗口,把路徑切換到當前路徑打開命令提示行,
4.1?切換到英文輸入法 win+R 打開命令窗口?輸入cmd

4.2?切換到項目目錄

一定要切換到項目目錄再執(zhí)行打包命令
4.3?輸入命令打包
?pyinstaller -F -i ./fac.ico tree.py
輸入命令后看見?successfully?那就是成功了

4.4 看打包的結果

這個時候多了很多文件和文件夾
dist目錄就是我們打包好的地方

tree.exe?就是我們打包好的文件
5.5?運行查看我們打包好的exe文件
對,雙擊就可以打開

5、參數(shù)的含義
-F 表示生成單個可執(zhí)行文件
-w 表示去掉控制臺窗口,這在GUI界面時非常有用。不過如果是命令行程序的話那就把這個選項刪除吧!
-p 表示你自己自定義需要加載的類路徑,一般情況下用不到
-i 表示可執(zhí)行文件的圖標
6.?附圣誕樹源文件
tree.py
import turtle
screen = turtle.Screen()
screen.setup(375, 700)
circle = turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up()
square = turtle.Turtle()
square.shape('square')
square.color('green')
square.speed('fastest')
square.up()
circle.goto(0, 280)
circle.stamp()
k = 0
for i in range(1, 13):
y = 30 * i for j in range(i - k):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
if i % 4 == 0:
x = 30 * (j + 1)
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
k += 3
if i % 4 == 3:
x = 30 * (j + 1)
circle.color('yellow')
circle.goto(-x, -y + 280)
circle.stamp()
circle.goto(x, -y + 280)
circle.stamp()
square.color('brown')
for i in range(13, 17):
y = 30 * i
for j in range(2):
x = 30 * j
square.goto(x, -y + 280)
square.stamp()
square.goto(-x, -y + 280)
square.stamp()
turtle.up()
turtle.goto(-20,-250)
turtle.write("節(jié)日快樂")
# 這里可以送上你的祝福
turtle.hideturtle()
turtle.done()
7.?源文件下載
到此這篇關于用python打包exe應用程序-PyInstaller的文章就介紹到這了,更多相關python打包exe內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python通過scapy獲取局域網(wǎng)所有主機mac地址示例
這篇文章主要介紹了python通過scapy獲取局域網(wǎng)所有主機mac地址示例,需要的朋友可以參考下2014-05-05
PyTorch中的torch.cat函數(shù)基本用法詳解
在PyTorch中,torch.cat是一個非常實用的函數(shù),用于將多個張量(Tensor)沿指定維度連接起來,本文將詳細介紹torch.cat函數(shù)的用法,并通過一些示例來說明其應用,感興趣的朋友跟隨小編一起看看吧2024-08-08
如何將anaconda安裝配置的mmdetection環(huán)境離線拷貝到另一臺電腦
這篇文章主要介紹了如何將anaconda安裝配置的mmdetection環(huán)境離線拷貝到另一臺電腦,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10

