打包python脚本的血与泪(python能做脚本吗)

打包python脚本的血与泪(python能做脚本吗)使用py2exe

本文目录一览:

如何把python脚本打包成exe

使用py2exe

安装py2exe

进入python程序所在文件夹

在文件夹下写一个setup.py的python文件,内容如下

from distutils.core import setup

import py2exe

setup(console=[“将要转换的文件名称.py”])

打开CMD窗口,将工作目录切换到python文件所在文件夹,并输入命令“python setup.py py2exe”

命令成功完成后,进入原python文件的文件夹下可看到新产生了文件夹

进入dist文件夹,里面的exe就是我们需要的windows程序。

Pycharm怎么打包Python脚本

python3是必须的,pyqt是做界面的,pycharm是优秀的IDE,pyinstaller生成可执行文件,。

1.先按照教程安装python3,QT,pycharm软件,因为目前PyQt5只支持python3.4,所以安装python3.4。

参考教程PyQt5+python3+pycharm开发环境配置

在环境变量中增加:

QT_QPA_PLATFORM_PLUGIN_PATH

C:\Python34\Lib\site-packages\PyQt5\plugins

2.按照教程创建界面,创建窗口时选“Widget”,然后按照说明创建调用的主程序,就可以运行了。

PyQt5学习笔记03—-Qt Designer生成源码

3.dos命令行输入:py -m pip install pyinstaller,安装pyinstaller。

4.在要制作的exe文件目录输入pyinstaller -F -w *.py,就可以制作出exe。生成的文件放在同目录dist下。

-F(注意大写)是所有库文件打包成一个exe,-w是不出黑色控制台窗口。

不加-F参数生成一堆文件,但运行快。压缩后比单个exe文件还小一点点。

加-F参数生成一个exe文件,运行起来慢。

按照第一步的方法,将pyinstaller加入pycharm的external tool,我加了两个,一个生成单独exe文件,一个生成运行带库的程序目录。

好了,环境搞好了,做界面,编程,调试,生成exe,慢慢练习吧!

python pyinstaller问题

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

又应验了那句歌词. 不经历风雨, 怎么见得了彩虹.

安装过程略去不提, 仅提示: pip install pyinstaller

打包指令

粗看包里的文档, 然后开始打包:

打开console

就用了这个命令: pyinstaller monitor_rt_quotes.py

结果就是比预期麻烦的多的多的: 干活, 硬盘不停地balabala叫, 漫长

这里记录一下控制台显示的提示信息:

官方文档对上述指令的解释为:

|PyInstaller| analyzes myscript.py and:

Writes myscript.spec in the same folder as the script.

Creates a folder build in the same folder as the script if it does not exist.

Writes some log files and working files in the build folder.

Creates a folder dist in the same folder as the script if it does not exist.

Writes the myscript executable folder in the dist folder.

In the dist folder you find the bundled app you distribute to your users.

巨长的提示后, 得到了exe文件, 有18Mb的大小(太庞大了, 肥肥肥!!!), 但是结果很悲剧:

D:\DB\fz\build\monitor_rt_quotesmonitor_rt_quotes.exe sz000911

Error loading Python DLL: D:\DB\fz\build\monitor_rt_quotes\python27.dll (error code 126)

估计是没有添加必要的打包选项造成的. 继续努力.

不死心! 解决问题需要由简到繁, 先从hellowworld.py做起. 搞定了.

被打包的文件: helloworld.py, 人人皆知.

打包的命令: pyinstaller -D helloworld.py

打包的console提示: 见随后的引述块

打包发布exe时的纪律(注意事项):

很简单的py脚本. Simple is better than complex. 应该遵守Python的规则.

所以在打包为exe时, 应该尽量减少没有必要的python包的导入. 否则吃的太胖

可以运行的exe文件位于: dist 目录下, 而不是build目录下的.

运行后的结果:

D:\DB\fzpyinstaller -D helloworld.py155 INFO: PyInstaller: 3.2.1155 INFO: Python: 2.7.11155 INFO: Platform: Windows-XP-5.1.2600-SP3155 INFO: wrote D:\DB\fz\helloworld.spec155 INFO: UPX is not available.155 INFO: Extending PYTHONPATH with paths

[‘D:\\DB’, ‘D:\\DB\\fz’]155 INFO: checking Analysis155 INFO: Building Analysis because out00-Analysis.toc is non existent155 INFO: Initializing module dependency graph…155 INFO: Initializing module graph hooks…312 INFO: running Analysis out00-Analysis.toc327 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable  required by d:\anaconda2\python.exe327 INFO: Found C:\WINDOWS\WinSxS\Policies\x86_policy.9.0.Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_x-ww_b7353f75\9.0.30729.1.policy327 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww …327 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e.manifest327 INFO: Searching for file msvcr90.dll327 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll327 INFO: Searching for file msvcp90.dll327 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcp90.dll327 INFO: Searching for file msvcm90.dll343 INFO: Found file C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcm90.dll343 INFO: Found C:\WINDOWS\WinSxS\Policies\x86_policy.9.0.Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_x-ww_b7353f75\9.0.30729.1.policy343 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0,30729, 1)484 INFO: Caching module hooks…500 INFO: Analyzing D:\DB\fz\helloworld.py500 INFO: Loading module hooks…500 INFO: Loading module hook “hook-encodings.py”…5405 INFO: Loading module hook “hook-httplib.py”…5421 INFO: Looking for ctypes DLLs5437 INFO: Analyzing run-time hooks …5452 INFO: Looking for dynamic libraries6155 INFO: Looking for eggs6155 INFO: Using Python library d:\anaconda2\python27.dll6171 INFO: Found binding redirects:[BindingRedirect(name=u’Microsoft.VC90.CRT’, language=None, arch=u’x86′, oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 1), publicKeyToken=u’1fc8b3b9a1e18e3b’)]6187 INFO: Warnings written to D:\DB\fz\build\helloworld\warnhelloworld.txt6280 INFO: checking PYZ6296 INFO: Building PYZ because out00-PYZ.toc is non existent6296 INFO: Building PYZ (ZlibArchive) D:\DB\fz\build\helloworld\out00-PYZ.pyz6968 INFO: Building PYZ (ZlibArchive) D:\DB\fz\build\helloworld\out00-PYZ.pyz completed successfully.7062 INFO: checking PKG7062 INFO: Building PKG because out00-PKG.toc is non existent7077 INFO: Building PKG (CArchive) out00-PKG.pkg7125 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.7140 INFO: Bootloader d:\anaconda2\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe7140 INFO: checking EXE7155 INFO: Building EXE because out00-EXE.toc is non existent7155 INFO: Building EXE from out00-EXE.toc7171 INFO: Appending archive to EXE D:\DB\fz\build\helloworld\helloworld.exe7171 INFO: Building EXE from out00-EXE.toc completed successfully.7187 INFO: checking COLLECT7202 INFO: Building COLLECT because out00-COLLECT.toc is non existent7202 INFO: Building COLLECT out00-COLLECT.toc7218 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0, 30729, 1)7375 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0, 30729, 1)7390 INFO: Updating manifest in C:\Documents and Settings\Administrator\Application Data\pyinstaller\bincache00_py27_32bit\python27.dll7405 INFO: Updating resource type 24 name 2 language 10337468 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0, 30729, 1)7484 INFO: Updating manifest in C:\Documents and Settings\Administrator\Application Data\pyinstaller\bincache00_py27_32bit\unicodedata.pyd7500 INFO: Updating resource type 24 name 2 language 10337546 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0, 30729, 1)7562 INFO: Updating manifest in C:\Documents and Settings\Administrator\Application Data\pyinstaller\bincache00_py27_32bit\_hashlib.pyd7562 INFO: Updating resource type 24 name 2 language 10337609 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) – (9, 0, 30729, 1)7625 INFO: Updating manifest in C:\Documents and Settings\Administrator\Application Data\pyinstaller\bincache00_py27_32bit\_ctypes.pyd7640 INFO: Updating resource type 24 name 2 language 10337687 INFO: Redirecting Microsoft.VC90

如何将一整个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_tmptree /F

文件夹 PATH 列表

卷序列号码为 0007F240 101F:F68D

E:.

CameraDll.dll

screenshot.ico

Screenshot.py

screenshot_setup.py

没有子文件夹

E:\tmp\pyexe_tmp

b、执行打包脚本:

E:\tmp\pyexe_tmppython 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’

打包python脚本的血与泪(python能做脚本吗)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/23261.html

(0)
上一篇 2023-11-22
下一篇 2023-11-24

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注