博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python打包成exe程序
阅读量:6918 次
发布时间:2019-06-27

本文共 7329 字,大约阅读时间需要 24 分钟。

hot3.png

环境 win7+py3.7

工具:pyinstaller

1、安装pyinstaller,cmd --> pip install pyinstaller

2、安装完成后,打开cmd,输入命令:pyinstaller -F  *.py(星号为py文件的全路径,如下图)

卸载 pip uninstall pyinstaller

版本查看 py -3.6 -m pip list

 

测试

vscode 编辑器安装

安装     pip install pyinstaller

打包1   没有全路径

D:\python\py_zhizhu>pyinstaller -F py_ex_file.py52 INFO: PyInstaller: 3.454 INFO: Python: 3.7.254 INFO: Platform: Windows-7-6.1.7601-SP199 INFO: wrote D:\python\py_zhizhu\py_ex_file.spec107 INFO: UPX is not available.110 INFO: Extending PYTHONPATH with paths['D:\\python\\py_zhizhu', 'D:\\python\\py_zhizhu']110 INFO: checking Analysis111 INFO: Building Analysis because Analysis-00.toc is non existent111 INFO: Initializing module dependency graph...111 INFO: Initializing module graph hooks...114 INFO: Analyzing base_library.zip ...3178 INFO: running Analysis Analysis-00.toc3200 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable  required by c:\users\administrator\appdata\local\programs\python\python37\python.exe3822 INFO: Caching module hooks...3826 INFO: Analyzing D:\python\py_zhizhu\py_ex_file.py3868 INFO: Loading module hooks...3868 INFO: Loading module hook "hook-encodings.py"...4041 INFO: Loading module hook "hook-pydoc.py"...4042 INFO: Loading module hook "hook-xml.py"...4230 INFO: Looking for ctypes DLLs4231 INFO: Analyzing run-time hooks ...4235 INFO: Looking for dynamic libraries4876 INFO: Looking for eggs4876 INFO: Using Python library c:\users\administrator\appdata\local\programs\python\python37\python37.dll4876 INFO: Found binding redirects:[]4879 INFO: Warnings written to D:\python\py_zhizhu\build\py_ex_file\warn-py_ex_file.txt4911 INFO: Graph cross-reference written to D:\python\py_zhizhu\build\py_ex_file\xref-py_ex_file.html4931 INFO: checking PYZ4932 INFO: Building PYZ because PYZ-00.toc is non existent4932 INFO: Building PYZ (ZlibArchive) D:\python\py_zhizhu\build\py_ex_file\PYZ-00.pyz5267 INFO: Building PYZ (ZlibArchive) D:\python\py_zhizhu\build\py_ex_file\PYZ-00.pyz completed successfully.5273 INFO: checking PKG5273 INFO: Building PKG because PKG-00.toc is non existent5273 INFO: Building PKG (CArchive) PKG-00.pkgTraceback (most recent call last):  File "c:\users\administrator\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main    "__main__", mod_spec)  File "c:\users\administrator\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code    exec(code, run_globals)  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts\pyinstaller.exe\__main__.py", line 9, in 
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\__main__.py", line 111, in run run_build(pyi_config, spec_file, **vars(args)) File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build exec(text, spec_namespace) File "
", line 32, in
File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__ strip_binaries=self.strip, upx_binaries=self.upx, File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__ self.__postinit__() File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__ self.assemble() File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\api.py", line 259, in assemble dist_nm=inm) File "c:\users\administrator\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\building\utils.py", line 281, in checkCache shutil.copy(fnm, cachedfile) File "c:\users\administrator\appdata\local\programs\python\python37\lib\shutil.py", line 245, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "c:\users\administrator\appdata\local\programs\python\python37\lib\shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst:PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Administrator\\AppData\\Roaming\\pyinstaller\\bincache00_py37_64bit\\api-ms-win-core-console-l1-1-0.dll'

错误 107 INFO: UPX is not available.

查了一圈,好像是版本的问题,卸载3.7.2,改为3.6.8再试。结果成功

D:\python\build_py\text>pyinstaller -F py_ex_file.py72 INFO: PyInstaller: 3.472 INFO: Python: 3.6.872 INFO: Platform: Windows-7-6.1.7601-SP174 INFO: wrote D:\python\build_py\text\py_ex_file.spec81 INFO: UPX is not available.82 INFO: Extending PYTHONPATH with paths['D:\\python\\build_py\\text', 'D:\\python\\build_py\\text']82 INFO: checking Analysis102 INFO: Building because _python_version changed102 INFO: Initializing module dependency graph...104 INFO: Initializing module graph hooks...105 INFO: Analyzing base_library.zip ...2478 INFO: running Analysis Analysis-00.toc2486 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable  required by c:\users\administrator\appdata\local\programs\python\python36\python.exe3034 INFO: Caching module hooks...3038 INFO: Analyzing D:\python\build_py\text\py_ex_file.py3069 INFO: Loading module hooks...3069 INFO: Loading module hook "hook-encodings.py"...3165 INFO: Loading module hook "hook-pydoc.py"...3166 INFO: Loading module hook "hook-xml.py"...3355 INFO: Looking for ctypes DLLs3355 INFO: Analyzing run-time hooks ...3360 INFO: Looking for dynamic libraries3453 INFO: Looking for eggs3453 INFO: Using Python library c:\users\administrator\appdata\local\programs\python\python36\python36.dll3453 INFO: Found binding redirects:[]3457 INFO: Warnings written to D:\python\build_py\text\build\py_ex_file\warn-py_ex_file.txt3493 INFO: Graph cross-reference written to D:\python\build_py\text\build\py_ex_file\xref-py_ex_file.html3509 INFO: checking PYZ3532 INFO: Building because toc changed3532 INFO: Building PYZ (ZlibArchive) D:\python\build_py\text\build\py_ex_file\PYZ-00.pyz3865 INFO: Building PYZ (ZlibArchive) D:\python\build_py\text\build\py_ex_file\PYZ-00.pyz completed successfully.3870 INFO: checking PKG3870 INFO: Building PKG because PKG-00.toc is non existent3870 INFO: Building PKG (CArchive) PKG-00.pkg5449 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.5476 INFO: Bootloader c:\users\administrator\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe5476 INFO: checking EXE5476 INFO: Building EXE because EXE-00.toc is non existent5476 INFO: Building EXE from EXE-00.toc5477 INFO: Appending archive to EXE D:\python\build_py\text\dist\py_ex_file.exe5481 INFO: Building EXE from EXE-00.toc completed successfully.

测试:

64位打包的exe不能到32位运行。

切换python3.6.8 为32位,重新安装导入包,重新安装打包工具,再次打包。

32位的可以在32 和 64位上跑。

转载于:https://my.oschina.net/qingqingdego/blog/3016722

你可能感兴趣的文章
Linux NFS服务器配置
查看>>
C++实现计数排序
查看>>
PPT组件Aspose.Slides V17.8发布 | 支持PP2010 PPTX与嵌入式视频
查看>>
Postfix全功能 (1)
查看>>
DOS系统功能调用表(INT 21H)
查看>>
作为JavaScript开发人员,这些必备的VS Code插件你都用过吗
查看>>
未来云世界畅想
查看>>
进程与计划任务
查看>>
组合模式
查看>>
linux文件操作之ls、mkdir、rmdir、cp命令使用
查看>>
观察最大堆的插入/删除元素后最大堆的变化
查看>>
oracle导入时IMP-00010: 不是有效的导出文件, 头部验证失败
查看>>
R:corrplot包
查看>>
用SPK技术分析,泰坦尼克号沉船之后哪些人活下来了
查看>>
多线程(八)---单例模式并发访问
查看>>
堵车预测神器诞生 浙江已用来治疗高速顽疾
查看>>
Android Span的简单使用
查看>>
centos7 挂载数据盘
查看>>
Prometheus+Grafana监控MySQL
查看>>
cas server 实现LDAP、数据库认证
查看>>