一、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)的更多相关文章

  1. 打包python脚本为exe可执行文件-pyinstaller和cx_freeze示例

    本文介绍使用cx_freeze和pyinstaller打包python脚本为exe文件 cx_freeze的使用实例 需要使用到的文件wxapp.py, read_file.py, setup.py ...

  2. 打包python脚本为exe的坎坷经历, by pyinstaller方法

    打包python脚本为exe的坎坷经历, by pyinstaller方法 又应验了那句歌词. 不经历风雨, 怎么见得了彩虹. 安装过程略去不提, 仅提示: pip install pyinstall ...

  3. PyInstaller把Python脚本打包成可执行程序教程

    一.说明 一直以来都有把.py文件打包成.exe文件的想法,但总是不够强烈,每次拖着拖着就淡忘了. 昨天帮硬件部门的同事写了个脚本,然后今天下午的时候,他问有没有办法把脚本打包成可执行文件,这样方便以 ...

  4. pyinstaller将python脚本生成exe

    一.下载pyinstaller 二.生成exe 下载pyinstaller 1.在C:\python27\Scripts目录下打开cmd界面,执行命令:pip install PyInstaller ...

  5. python脚本生成exe可执行文件

    1.先安装第三方插件: py2exe. Get py2exe from http://www.py2exe.org/ 在download里下载与自己python对应的版本 2.写一个测试python文 ...

  6. python 使用py2exe将python 脚本生成exe可执行文件

    使用python的py2exe模块可以很容易地帮助我们将python脚本生成可执行的exe程序.这样我们就可以让脚本脱离虚拟机的束缚,从而独立运行. 首先安装py2exe分解步骤如下:(pip和eas ...

  7. python脚本生成exe程序

    去年十一月换了新公司后,一直没闲着,马不停蹄地接不同的需求,一个版本一个版本的迭代,也没时间研究python了.十一休假归来,某日,老婆问金融量化需要学python吗?并分享了一个公众号文章,内容是吹 ...

  8. PyInstaller打包Python脚本为exe

    1.PyInstaller-3.1.1  百度云链接  http://pan.baidu.com/s/1jHYWin8 密码  oapl 2.安装最新版本的 pywin32-217.win32-py2 ...

  9. Python文件打包exe教程——Pyinstaller(亲测有效)

    今天将要解决一个问题,如何打包Pyhon文件 众所周知,Python文件的后缀名为“.py” 所以执行Python文件的要求之一便是具有python环境. 偶尔特殊情况,或者运行一些比较简单的工具,但 ...

随机推荐

  1. 数据库求闭包,求最小函数依赖集,求候选码,判断模式分解是否为无损连接,3NF,BCNF

    1.说白话一点:闭包就是由一个属性直接或间接推导出的所有属性的集合. 例(1):   设有关系模式R(U,F),其中U={A,B,C,D,E,I},F={A→D,AB→E,BI→E,CD→I,E→C} ...

  2. Python文件和数据格式化(教程)

    文件是一个存储在副主存储器的数据序列,可包含任何数据内容. 概念上,文件是数据的集合和抽象,类似的,函数是程序的集合和抽象. 用文件形式组织和表达数据更有效也更加灵活. 文件包括两种形式,文本文件和二 ...

  3. Selenium WebDriver 中鼠标事件

    鼠标点击操作  鼠标点击事件有以下几种类型:  清单 1. 鼠标左键点击   Actions action = new Actions(driver);action.click();// 鼠标左键在当 ...

  4. FastDFS搭建分布式文件系统

    FastDFS搭建分布式文件系统 1. 什么是分布式文件系统 分布式文件系统(Distributed File System)是指文件系统管理的物理存储资源不一定直接连接在本地节点上,而是通过计算机网 ...

  5. Stream系列(十二) PartitioningBy方法使用

    分割列表 视频讲解: https://www.bilibili.com/video/av78106120/ EmployeeTestCase.java package com.example.demo ...

  6. 批量更新Linux文件后缀名

    #!/bin/bash#Create_Time 2019-08-06#use: small_wei #查找并,批量修改文件后缀 #后缀为 .txt 修改为 .log find /opt -name & ...

  7. PHP后端代码生成微信小程序带参数的二维码保存成jpg图片上传到服务器getwxacodeunlimit

    老板最近有点飘了,他要在PC端的网站放一个微信小程序的二维码,并且扫描这个二维码以后要跳到小程序对应的房源详情页. 这是微信官方给出的文档,连接地址:https://developers.weixin ...

  8. PHP页面跳转传值的三种常见方式

    一. POST传值 post传值是用于html的<form>表单跳转的方法,很方便使用.例如: ? 1 2 3 4 5 6 7  <html>  <form action ...

  9. java this,super简单理解

    *****this****** 表示对当前对象的引用. 作用:1.区分实例变量和局部变量(this.name----->实例变量name) 2.将当前对象当做参数传递给其它对象和方法.利用thi ...

  10. Python网络爬虫——BeautifulSoup4库的使用

    使用requests库获取html页面并将其转换成字符串之后,需要进一步解析html页面格式,提取有用信息. BeautifulSoup4库,也被成为bs4库(后皆采用简写)用于解析和处理html和x ...