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)相关推荐
- 使用py2exe打包python脚本为exe可执行程序
2019独角兽企业重金招聘Python工程师标准>>> python为解释性语言,对应的脚本文件需要在python的程序库中执行.为了方便在没有安装python的PC机上运行pyth ...
- python 如何将代码打包成exe可执行程序?(导出为exe可执行文件)pyinstaller
步骤 1 安装pyinstaller pip install pyinstaller 或pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ...
- Python代码转如何换为exe可执行程序详解
一,简介 Python写完程序,要靠命令来执行太LOW,太低调了,还不华丽了. 再说别人的电脑,都没有Python库,怎么执行,还能不能愉快的一起玩耍了. 所以哪怕只会写一个HelloWorld,也要 ...
- Python 基础语法_Python脚本文件结构
目录 目录 前言 软件环境 Python Script文件结构 导入模块的流程 Python的包package 最后 前言 Python基础语法这一章,主要记录了Python的文件结构.逻辑运算符.算 ...
- python 投屏_python脚本调用scrcpy进行多设备投屏
之前由于自己工作需要两个手机演示我写的微信小程序,所以写了一篇文章分享了我的小工具,没想到得到大家的欢迎,本次对该脚本重新进行了小小的修改优化,且将脚本代码发不出来,本人python小白,高手请忽略我 ...
- python 打包图标_Python打包成exe文件很难?一分钟即可学会,并添加图标!
环境 1.python 3.7 2.pyinstaller 下载方式: 2.1 python安装(略) 2.2 安装pyinstaller 打开DOS窗口输入以下命令: pip install pyi ...
- python 手机测试_python脚本如何测试手机
一.adb 相关命令: 1.关闭adb服务:adb kill-server 2.启动adb服务 adb start-server 3.查询当前运行的所有设备 adb devices 4.可能在ad ...
- python linux服务_Python脚本作为Linux服务/守护程序
哈o 我试图让python脚本在(ubuntu)linux上作为服务(守护程序)运行. 在网络上,存在几种解决方案,例如: 行为规范的Unix守护进程很难正确执行,但是每个守护程序所需的步骤几乎相同. ...
- python时间显示_python脚本之日期格式显示
脚本内容: #!/usr/bin/python #coding=utf-8 #根据给定的年月日以数字形式打印出日期 months =[ "January", "Febru ...
最新文章
- 计算机用英语bos,宏基电脑boss界面英文翻译,不知道的可以看看。
- PHP APM fiery 更新 v0.5.8.0
- 开始新的BLOG了!!
- catia怎么将特征参数化_搭建商城网站怎么将页面简洁化?这三个步骤不能少
- struts2核心配置
- vue组件内数值做watch监听,首次监听不到的问题
- 如何在vs2010中使用ConfigurationManager
- 信号调制三种方法的带宽比较
- 磁力搜索引擎-RunBt
- Java、IO流——缓冲流
- FFmpeg 加水印 加马赛克
- unity3d 取锚点位置_如何不靠看格子,确定一个字的首笔和后面每一笔画的位置?...
- 污染土壤修复可以采取哪些方式
- xxljob默认登录_XXL-JOB快速入门
- 暴力破解Wi-Fi密码(Mac M1)
- 声波牙刷的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
- mc服务器怎么回到床的位置,《我的世界》MC床的功能居然跟这四个指令有关系?很多人不知道!...
- 根据IMSI区别运营商
- Cannot assign to read only property ‘0’ of string的报错原因之一及解决办法
- 2021秋招河南联通面经
热门文章
- MFC框架机制详细论述
- Opencv显示创建Mat对象的七种方式
- Flutter的文本控件的基本使用
- int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
- java 反射内部匿名内部类_android-反射的使用(反射静态内部类、非静态内部类、匿名内部类等)...
- const int是什么类型_C++的const语义
- Android开发之设置DialogFragment的窗体背景色的方法亲测可用
- Android开发之虹软人脸识别活体检测基本步骤
- Android开发之xml动画(补间动画)记录
- 删除用户的命令是什么mysql_mysql新添加用户与删除用户具体操作命令_MySQL