
如何发布一个Python程序:
1、安装一个pyInstaller
在pycharm里烂答点 file—–>setting—–>Project workspace——>Interpreter——>点pip右边的+号,进入下面这个界面:
搜索pyInstaller, 点击首戚左下方Install package安装(出现错误了可以多安装几次)
(或者在命令提示符界面 用 pip install pyinstaller命令安装)
2、将.py文件打包成.exe文件
在完成第一步的安装后,就开始我们的打包。在打包之前可以先运者历陵行一下你要打包的.py文件是否可以运行,然后进行打包。
在pycharm中右键点击你将要打包的文件,找到Open in terminal点一下。
在下面出现的Local框内输入命令:pyinstaller -F 文件名,运行。
然后进行打包
打包完成后,稍等一下会刷新出一个dist文件夹, 点击 ,在里面有一个 .exe文件,右键,点击里面的 Show in Explore 找到一个.exe文件(如果不一样的可以看一下你下面打包成功后出现的路径。)
3、发送
将打包好的.exe文件拉到你之前.py文件所在的文件夹,将所有需要的素材一起发送。
别人收到后就能打开你的.exe文件运行你的程序。
众多python培训视频,尽在python学习网,欢迎在线学习!
1、下载并安装py2exe,可下载最新版本。2、编写安装脚本,比较简单,不过多解释,如下:
Screenshot_setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
includes = ["encodings", "encodings.*"]
data_files = ['CameraDll.dll']
options = {"py2exe"陪销肆:
{ "compressed": 1,
"optimize": 2,
"bundle_files": 1,
"includes": includes
}
}
setup(
version = "1.0",
description = "Screenshot Tool",
name = "Screenshot Tool",
options = options,
zipfile=None,
data_files = data_files,
console=[{"script": "Screenshot.py", "icon_resources": [(1, "Screenshot.ico")] }]
)
各参数含义见第5小节或执行python命令行下执行help(py2exe)查看。
3、打包程序:斗渗
a、将要找包的程序、文件和打包脚本放在同一目录下,如下:
E:\tmp\pyexe_tmp>tree /F
文件夹 PATH 列表
卷序列号码为 0007F240 101F:F68D
E:.
CameraDll.dll
screenshot.ico
Screenshot.py
screenshot_setup.py
没有子文件夹
E:\tmp\pyexe_tmp>
b、执行打包脚本:
E:\tmp\pyexe_tmp>python screenshot_setup.py py2exe
python screenshot_setup.py py2exe
running py2exe
creating E:\tmp\pyexe_tmp\build
creating E:\tmp\pyexe_tmp\build\bdist.win32
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\collect-2.6
creating E:\tmp\芦轿pyexe_tmp\build\bdist.win32\winexe\bundle-2.6
creating E:\tmp\pyexe_tmp\build\bdist.win32\winexe\temp
creating E:\tmp\pyexe_tmp\dist
*** searching for required modules ***
*** parsing results ***
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script 'e:\tmp\tmp1ecbcw.py'
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)