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
https://www.wukong.com/answer/6732408567304814861/
https://www.cnblogs.com/robinunix/p/8426832.html
Python—脚本程序生成exe可执行程序(pyinstaller)的更多相关文章
- 打包python脚本为exe可执行文件-pyinstaller和cx_freeze示例
本文介绍使用cx_freeze和pyinstaller打包python脚本为exe文件 cx_freeze的使用实例 需要使用到的文件wxapp.py, read_file.py, setup.py ...
- 打包python脚本为exe的坎坷经历, by pyinstaller方法
打包python脚本为exe的坎坷经历, by pyinstaller方法 又应验了那句歌词. 不经历风雨, 怎么见得了彩虹. 安装过程略去不提, 仅提示: pip install pyinstall ...
- PyInstaller把Python脚本打包成可执行程序教程
一.说明 一直以来都有把.py文件打包成.exe文件的想法,但总是不够强烈,每次拖着拖着就淡忘了. 昨天帮硬件部门的同事写了个脚本,然后今天下午的时候,他问有没有办法把脚本打包成可执行文件,这样方便以 ...
- pyinstaller将python脚本生成exe
一.下载pyinstaller 二.生成exe 下载pyinstaller 1.在C:\python27\Scripts目录下打开cmd界面,执行命令:pip install PyInstaller ...
- python脚本生成exe可执行文件
1.先安装第三方插件: py2exe. Get py2exe from http://www.py2exe.org/ 在download里下载与自己python对应的版本 2.写一个测试python文 ...
- python 使用py2exe将python 脚本生成exe可执行文件
使用python的py2exe模块可以很容易地帮助我们将python脚本生成可执行的exe程序.这样我们就可以让脚本脱离虚拟机的束缚,从而独立运行. 首先安装py2exe分解步骤如下:(pip和eas ...
- python脚本生成exe程序
去年十一月换了新公司后,一直没闲着,马不停蹄地接不同的需求,一个版本一个版本的迭代,也没时间研究python了.十一休假归来,某日,老婆问金融量化需要学python吗?并分享了一个公众号文章,内容是吹 ...
- PyInstaller打包Python脚本为exe
1.PyInstaller-3.1.1 百度云链接 http://pan.baidu.com/s/1jHYWin8 密码 oapl 2.安装最新版本的 pywin32-217.win32-py2 ...
- Python文件打包exe教程——Pyinstaller(亲测有效)
今天将要解决一个问题,如何打包Pyhon文件 众所周知,Python文件的后缀名为“.py” 所以执行Python文件的要求之一便是具有python环境. 偶尔特殊情况,或者运行一些比较简单的工具,但 ...
随机推荐
- Java中父类和子类代码执行顺序
执行顺序:父类静态块-->子类静态块-->父类非静态块-->父类构造方法-->子类非静态块-->子类构造方法 当父类或子类中有多个静态方法时按在代码中的顺序执行 pack ...
- 查找节点(getAttribute())
getAttribute():方法将返回一个给定元素的一个给定属性节点的值: attributeValue = element.getAttribute(attributeName); 给定属性的名字 ...
- SpringBoot 整合mongoDB并自定义连接池
SpringBoot 整合mongoDB并自定义连接池 得力于SpringBoot的特性,整合mongoDB是很容易的,我们整合mongoDB的目的就是想用它给我们提供的mongoTemplate,它 ...
- Scrapy持久化存储-爬取数据转义
Scrapy持久化存储 爬虫爬取数据转义问题 使用这种格式,会自动帮我们转义 'insert into wen values(%s,%s)',(item['title'],item['content' ...
- 手机端web(iPad)页面自适应js
有关编写手机页面(ipad页面)自适应的方法有很多,比如:bootstrap,rem等等.下面分享给大家一个js控制viewPort视区自适应缩放的方法(我给它命名为phone.js): 将phone ...
- PAT(甲级)2017年春季考试
PAT(甲级)2017年春季考试 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int ...
- 基本shell脚本
#!/bin/bash attr=() num= while true do read -p ">>input:" name attr[$num]=$name echo ...
- Spring Boot中@ConditionalOnProperty使用详解
在Spring Boot的自动配置中经常看到@ConditionalOnProperty注解的使用,本篇文章带大家来了解一下该注解的功能. Spring Boot中的使用 在Spring Boot的源 ...
- ThinkPHP5——模型关联(一对一关联)
定义 定义一对一关联使用了hasOne,hasOne方法的参数包括: hasOne('关联模型名','外键名','主键名',['模型别名定义'],'join类型'); 下面定义一个用户表,公司给每个用 ...
- 【经验分享】linux交叉编译 - openssl动态库
一.准备工作 1.到openssl官网下载最新版本openssl(如openssl-1.1.1d.tar.gz),上传到linux编译机上(如上传到目录/home/test下),并使用tar -xvf ...