Pyinstaller + python docx打包exe出问题解决
2019-01-09 19:44
507 查看
参考链接:
https://stackoverflow.com/questions/35642322/pyinstaller-and-python-docx-module-do-not-work-together
在自己写PyQt5+python docx+Python3.7 打包exe的时候出现问题,发现点击按钮有闪退现象,最后发现是pyinstaller打包的时候没有把docx模块打包进去,参考上述链接但是有所不同的是变化如下:
首先生成**.spec**文件 在脚本路径下运行 :pyi-makespec your_py_file_name.py
在记事本中打开.spec文件并通过添加以下内容进行编辑:
# -*- mode: python -*- import sys from os import path site_packages = next(p for p in sys.path if 'site-packages' in p) ##原来的代码是找的库'C:\\Users\\sufor\\AppData\\Roaming\\Python\\Python37\\site-packages'这个库中没有docx site_packages = 'C:\Users\sufor\AppData\Local\Programs\Python\Python37\Lib\site-packages' block_cipher = None a = Analysis(['xml_reader.py'], pathex=['C:\\Users\\Lenovo\\Desktop\\exe'], binaries=[], datas=[(path.join(site_packages,"docx","templates"), "docx/templates")], #原来datas替换为现在datas hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, exclude_binaries=True, name='xml_reader', debug=False, strip=False, upx=True, console=True ) coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name='xml_reader')
最后运行在当前脚步路径下运行cmd命令:pyinstaller your_py_file_name.spec
这时候pydocx就会包含到exe的运行环境里面
相关文章推荐
- 【实际运用篇】解决午饭问题的python小程序+Pyinstaller打包操作
- PythonInstaller2.1打包单个exe遇到的问题,留个记录
- Python 3.5 + PyInstaller 3.2.1打包exe出错,TypeError: read() takes no keyword arguments
- python 打包exe pyinstaller
- 关于解决pyinstaller2.1将.py打包成exe文件在中文目录下不能执行的问题
- python selenium运行,打包exe常见问题解决方法
- [Python]项目打包:5步将py文件打包成exe文件
- 解决打包时IsCmdBld.exe出错的问题
- python3.4写好的.py文件如何打包成exe?
- [Python]项目打包:5步将py文件打包成exe文件(转)
- python to exe pyinstaller
- python3.5把py文件打包成exe文件
- notepad++编译器保存的python代码出现python:can't open file '**.py' :[error 2] No Such file or directory问题怎么解决
- Python打包为exe使用py2exe时中文乱码问题
- python3.5把py文件转换为exe文件(by PyInstaller)
- Python中.py文件打包成exe可执行文件详解
- python3.5 + PyQt4 + pyinstaller打包错误,Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
- 共享你的python小程序--快速打包python .py为EXE!!
- 【Python3】py脚本打包成exe
- Python的py文件打包成exe