日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Python如何生成windows可执行的exe文件

發布時間:2023/12/20 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python如何生成windows可执行的exe文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

打包工具

  • pyinstaller

安裝pyinstaller

如果你的網絡穩定,通常直接使用下面的命令安裝即可:

pip?install?pyinstaller

當然了,你也可以下載pyinstaller源碼包,然后進入包目錄執行下面的命令,同樣可以安裝(前提是需要安裝setuptools):

python setup.py?install

?

檢查pyinstaller安裝成功與否:

只需要執行如下命令其中一個即可:

pyinstaller --version pyinstaller -v

?

pyinstaller參數作用

  • -F 表示生成單個可執行文件
  • -D –onedir 創建一個目錄,包含exe文件,但會依賴很多文件(默認選項)
  • -w 表示去掉控制臺窗口,這在GUI界面時非常有用。不過如果是命令行程序的話那就把這個選項刪除吧
  • -c –console, –nowindowed 使用控制臺,無界面(默認)
  • -p 表示你自己自定義需要加載的類路徑,一般情況下用不到
  • -i 表示可執行文件的圖標
  • 其他參數,可以通過pyinstaller --help查看

開始打包

進入python需要打包的腳本所在目錄,然后執行下面的命令即可:

pyinstaller?-F?-i?favicon.ico?xxx.py

?

打包結果

打包完成后,進入到當前目錄下,會發現多了__pycache__、build、dist、nhdz.spec這四個文件夾或者文件,其中打包好的exe應用在dist目錄下面,進入即可看到,可以把他拷貝到其他地方直接使用,如下圖所示,是打包完成后的目錄:

?

執行exe應用

因為是exe應用,是可執行文件了,所以直接雙擊運行即可,運行效果如下圖所示:

?

到這里,exe文件就已經生算是打包完成,并且可以運行了,如果你想在其他平臺運行,只需要拷貝dist下面的文件即可

ICO圖標制作

前面需要用到ICO圖標,大家可以網上搜索“ICO 在線生成”,可以直接點擊ICO圖標制作在上面制作、然后保存也行

?

測試程序源碼

# -*- coding: utf-8 -*- # @Time : 2019/07/14 19:47 # @Author : Liu # @File : exe.pyimport random import timedef enter_stake(current_money):'''輸入小于結余的賭資及翻倍率,未考慮輸入type錯誤的情況'''stake = int(input('How much you wanna bet?(such as 1000):'))rate = int(input("What multiplier do you want?你想翻幾倍?(such as 2):"))small_compare = current_money < stake * ratewhile small_compare == True:stake = int(input('You has not so much money ${}!How much you wanna bet?(such as 1000):'.format(stake * rate)))rate = int(input("What multiplier do you want?你想翻幾倍?(such as 2):"))small_compare = current_money < stake * ratereturn stake,ratedef roll_dice(times = 3):'''搖骰子'''print('<<<<<<<<<< Roll The Dice! >>>>>>>>>>')points_list = []while times > 0:number = random.randrange(1,7)points_list.append(number)times -= 1return points_listdef roll_result(total):'''判斷是大是小'''is_big = 11 <= total <= 18is_small = 3 <= total <= 10if is_small:return 'Small'elif is_big:return 'Big'def settlement(boo,points_list,current_money,stake = 1000,rate = 1):'''結余'''increase = stake * rateif boo:current_money += increaseprint('The points are ' + str(points_list) + ' .You win!')print('You gained $' + str(increase) + '.You have $' + str(current_money) + ' now.' )else:current_money -= increaseprint('The points are ' + str(points_list) + ' .You lose!')print('You lost $' + str(increase) + '.You have $' + str(current_money) + ' now.' )return current_moneydef sleep_second(seconds=1):'''休眠'''time.sleep(seconds)# 開始游戲 def start_game():'''開始猜大小的游戲'''current_money = 1000print('You have ${} now.'.format(current_money))sleep_second()while current_money > 0:print('<<<<<<<<<<<<<<<<<<<< Game Starts! >>>>>>>>>>>>>>>>>>>>')your_choice = input('Big or Small: ')choices = ['Big','Small']if your_choice in choices:stake,rate = enter_stake(current_money)points_list = roll_dice()total = sum(points_list)actual_result = roll_result(total)boo = your_choice == actual_resultcurrent_money = settlement(boo,points_list,current_money,stake,rate)else:print('Invalid input!')else:sleep_second()print('Game Over!')sleep_second(2)if __name__ == '__main__':start_game()

?

總結

以上是生活随笔為你收集整理的Python如何生成windows可执行的exe文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。