Python製作exe檔案簡單流程

2022-09-26 18:18:12 字數 1145 閱讀 7414

一:什麼是exe?

exe是windows環境中的副檔名之一,它是乙個可執程式設計客棧行檔案,雖然擴充套件程式在一般情況下是隱藏的,但是我們可以通過取消選中資源管理器資料夾的高階設定中的「不顯示已註冊的副檔名」來顯示它。

可執行檔案意味著它是乙個可以由其自身執行的檔案,而不是其他程式。例如,在python程式中要執行它,在命令提示符下按如下所示編寫,其中hello.py是檔名。

python hello.py

如果將其轉換為可執行檔案,即exe檔案,則可以通過在命令提示符下按如下方式編寫,也可以從資源管理器中雙擊相應的檔案。

用hello.exe

二:如何使檔案成為exe

使用pyinstaller在p程式設計客棧ython中執行exe檔案,首先讓我們安裝pyinstaller,使用以下命令從命令提示符安裝程式設計客棧。

pip install pyinstaller

要使其成為exe,請輸入以下內容,-onefile和-noconsole是可選的。

和-noconsole是可選的。

pyinstaller python檔名[--onefile] [-noconsole]

--onefile通過將相關檔案分組為乙個來建立exe檔案。 - noconsole不顯示控制台的黑屏(命令提示符)

三:實際製作檔案exe

嘗試輸入並且執行以下程式,將其儲存為hello.py

從datetime匯入日期時間

s =輸入("請輸入你的名字")

y = int(輸入(f"你好,!今年多大了?"))

#獲取自python誕生以來的年數(2023年)

py = datetime.now().year - 1991

if(y == py):

列印("嗯,這是相同的年齡!")

elif(y kkttjlvme印("它比我大!

輸入(「按任意鍵退出")

然後在命令提示符下的hello.py資料夾中輸入以下內容:

pyinstaller hello.py --onefile

執行時,會建立名為build和dist的資料夾,其中dist資料夾中有乙個hello.exe檔案,這是乙個exepted python檔案,雙擊執行即可。

本文標題: python製作exe檔案簡單流程

本文位址:

製作python指令碼為exe檔案

pip install pyinstaller 建立名為aaa.py的指令碼檔案 功能列印輸入的文字資訊。while 1 print input data input print input data 在當前路徑下開啟終端,鍵入如下命令 pyinstaller w f c aaa.py 表示一些引數...

python製作電腦可執行exe檔案

製作get ip.py檔案 import socket import uuid 獲取主機名 hostname socket.gethostname 獲取ip ip socket.gethostbyname hostname 獲取mac位址 defget mac address mac uuid.uu...

python編譯exe檔案

小demo coding utf 8 第乙個程式 import subprocess print hello world print hello again print i like typing this.print this is fun.print yay printing.print i d...