一行简单的代码就能实现Python打包exe,为什么那么多人不知道?
off999 2024-09-16 00:53 48 浏览 0 评论
关于python程序打包的介绍就不多说了,大部分的python基础书上都有介绍。这里就直接演练。
只是一个简单的demo,一个demo项目中,有一个hello文件,文件中有一个函数hello,函数的作用是读取testdd.txt文件中的数据然后输出。
这个项目中还有其他的一些东西,以演示打包。
整个项目结构如下:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
singledemo
demo
model
init.py
entity.py
static
test.txt
hello.py
MANIFEST.in
setup.py
</pre>
hello.py中的代码:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
def hello():
f = open('testdd.txt', 'r')
content = f.read()
f.close()
print content
</pre>
setup.py中的代码如下:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
coding:utf-8
'''
'''
import os
import sys
from setuptools import setup, find_packages
setup(
name = "demo",
version = "0.0.1",
packages = find_packages(),
include_package_data = True,
entry_points = {
'console_scripts' : [
'demo = demo.hello:hello'
],
},
package_data = {
'demo':['*.txt']
},
author = "the5fire",
author_email = '嘻嘻嘻嘻嘻嘻嘻@email.com',
url = "http://www.the5fire.com",
description = 'a demo for setuptools',
)
</pre>
还有一个文件需要注意,MANIFEST.in:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
recursive-include demo *.txt
</pre>
虽然只有一句话,但是是要通过它来包括你要打包的非py文件。
打包时候的命令有两个,
一个是打包成egg文件:python setup.py bdist_egg 。执行完成后,会在同目录下多了两个文件夹:demo.egg-info和dist,egg文件就在dist中,这个文件可以上传到pypi.python.com上,供大家下载。或者上传到某网盘,通过pip install --no--index find-links=[url]来下载。
另外一种是打包成压缩文件形式:python setup.py sdist 。执行结果同上,不过文件格式不同。
打包完成之后,当然要安装了,上一篇介绍了virtualenv,创建一个虚拟环境以供测试。然后执行python setup.py install 就会在你的虚拟环境的bin下创建一个demo的可执行文件,你在虚拟环境中运行:demo,输出结果。
很简单的东西,但是需要参考。
-END-
更多资讯请关注猿来如此呀账号,或点击下方链接了解更多资讯
相关推荐
-
- cad2014破解版激活教程(cad 2014破解版怎么样激活)
-
步骤如下:1.打开CAD2014,点击激活,勾选同意协议之后它会告诉您,您的序列号是错误的,这时点击关闭等一会再点击激活即可;2.在激活界面中选择“我拥有一个Autodesk激活码”;3.启动对应版本的XFORCEKeygen32bit...
-
2026-02-03 15:51 off999
- electricity(electricity翻译)
-
electricity[英][??lek?tr?s?ti][美][?l?k?tr?s?ti,?il?k-]n.电力;电流,静电;高涨的情绪;紧张;以上结果来自金山词霸例句:1.Article31pow...
- 腾讯游戏实名认证中心官网(腾讯游戏实名认证官网首页)
-
QQ游戏实名注册和防沉迷系统设置方法:第一步:登录实名注册和防沉迷系统网站(http://jkyx.qq.com/web2010/authoriz.htm);第二步:填写实名制信息;第三步:等待审核,...
- qlv文件怎么转换成mp4(qlv文件怎么转换成mp4格式)
-
要将QLV文件转换为MP4文件,您可以使用专业的视频转换软件。首先,下载并安装一个可靠的视频转换器,如Handbrake或AnyVideoConverter。然后,打开软件并导入您要转换的QLV文...
- 央视网cctv5直播(央视网cctv5直播在线观看)
-
看CCTV5直播可以直接选择网页看直播或者使用播放器看直播频道。1、打开e网站2、打开我打圈的,电视直播,但是这里面有些台没有,比如浙江卫视3、然后在左边可以选择你想看的台4、方法2,打开网络主流播放...
- qq历史版本官方下载(qq历史旧版本大全)
-
蟹妖。我用的小米手机,可以双开两个应用,你可以搞两个一样版本的qq。小米手机,还可以手机分身,一个手机不同的解锁方式进入不同的系统,第一个系统你可以安最新版本的qq,另一个系统你可以安装其他版...
- 一个人看的片免费高清大全(一个人看的片免费高清大全在线观看)
-
推荐“爱奇艺App手机版”。它是百度旗下的高清电影站,有许多最新最热的正版大片供免费观看,爱奇艺APP是一款集视频、商城、购票、阅读、直播、泡泡粉丝社区等多种服务于一体的移动软件。爱奇艺手机版为用户提...
- 搜狗翻译app下载(搜狗翻译app下载安装)
-
有啊,点击输入框弹出搜狗键盘,进入搜狗工具栏最左边的图标,进入加号,添加中英互译。1、首先确认是否电脑键盘按键出现问题,可以通过win+r调出运行,输入osk。2、调出虚拟键盘测试虚拟键盘是否可以正常...
- 女生付费和男生聊天(女生找男生聊天掉价吗)
-
不管在什么情况下女生好像都处在优势,因为只听说过娶不到媳妇儿的单身汉,还没有听说过嫁不出去的丑媳妇儿。所以一般这种交友聊天软件就是奔着让男人出钱来的,而且这类软件骗子太多,几乎都是机器人,或者是各种托...
- 腾讯公司版权所有(腾讯开放版权)
-
你好!其实这个很好理解,就是版权公司把这个音乐的管理、销售权限(独家版权)授权给了腾讯,腾讯可以把音乐对外进行转授权。所以你看有一些腾讯独家版权的歌,为什么其他音乐平也台会有呢?其实就是腾讯授予的。因...
- 智能语音机器人(智能语音机器人哪个最好)
-
1、小米的小爱小爱的智能应用随着近年来的不断升级,在很多手机应用都带来了智能新体验。像移动支付、生活购物、查询信息、打开应用等等,小爱智能语音识别就可以帮你解决。用户还可以自己创建快捷方式,进行语音交...
- adobe lightroom(adobe lightroom for ipad破解版)
-
adobelightroom是一款非常不错的在线教育软件,adobelinghtroom这款软件具有资源管理,资源共享,在线学习,在线考试,成绩管理,教学管控,教学互动,效果评估等等功能,可以为用户提...
- 解压软件免费(电脑解压软件免费)
-
WinRAR压缩软件winrar压缩软件界面友好,WINRAR现在最好的压缩工具。使用方便,压缩率和速度方面都有很好的表示。其压缩率比之WINZIP之流要高。winrar压缩软件采用了比Zip更...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
win7系统还原步骤图解(win7还原电脑系统的步骤)
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
python入门到脱坑 输入与输出—str()函数
-
16949认证费用是多少(16949审核员太难考了)
-
linux软件(linux软件图标)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
