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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python代码生成可执行程序_Python—脚本程序生成exe可执行程序(pyinstaller)

發布時間:2023/12/15 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python代码生成可执行程序_Python—脚本程序生成exe可执行程序(pyinstaller) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、pyinstaller的簡介

Python是一個腳本語言,被解釋器解釋執行。它的發布方式:

.py文件:對于開源項目或者源碼沒那么重要的,直接提供源碼,需要使用者自行安裝Python并且安裝依賴的各種庫。(Python官方的各種安裝包就是這樣做的)。

.pyc文件:有些公司或個人因為機密或者各種原因,不愿意源碼被運行者看到,可以使用pyc文件發布,pyc文件是Python解釋器可以識別的二進制碼,故發布后也是跨平臺的,需要使用者安裝相應版本的Python和依賴庫。

可執行文件:對于一些小白用戶,最簡單的方式就是提供一個可執行文件,只需要把用法告訴Ta即可。比較麻煩的是需要針對不同平臺需要打包不同的可執行文件(Windows,Linux,Mac,...)。

二、pyInstaller的原理簡介

三、pyinstaller的安裝

[root@localhost ~]# pip install pyinstaller

四、小實例(windows下)

# -*- coding:utf-8 -*-

import random

import time

def 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 * rate

while 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 * rate

return stake,rate

def roll_dice(times = 3):

'''搖骰子'''

print('<<<<<<<<<< Roll The Dice! >>>>>>>>>>')

points_list = []

while times > 0:

number = random.randrange(1,7)

points_list.append(number)

times -= 1

return points_list

def roll_result(total):

'''判斷是大是小'''

is_big = 11 <= total <= 18

is_small = 3 <= total <= 10

if is_small:

return 'Small'

elif is_big:

return 'Big'

def settlement(boo,points_list,current_money,stake = 1000,rate = 1):

'''結余'''

increase = stake * rate

if boo:

current_money += increase

print('The points are ' + str(points_list) + ' .You win!')

print('You gained $' + str(increase) + '.You have $' + str(current_money) + ' now.' )

else:

current_money -= increase

print('The points are ' + str(points_list) + ' .You lose!')

print('You lost $' + str(increase) + '.You have $' + str(current_money) + ' now.' )

return current_money

def sleep_second(seconds=1):

'''休眠'''

time.sleep(seconds)

def start_game():

'''開始猜大小的游戲'''

current_money = 1000

print('You have ${} now.'.format(current_money))

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_result

current_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()

五、pyinstaller打包

E:\>pyinstaller -F test.py # 有input函數的時候,就不帶-w,不然會報錯。

E:\>pyinstaller -F -w test.py

總結

以上是生活随笔為你收集整理的python代码生成可执行程序_Python—脚本程序生成exe可执行程序(pyinstaller)的全部內容,希望文章能夠幫你解決所遇到的問題。

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