如何将Python网站包文件夹(未包含在其中)添加到PyInstaller规范文件中?

问题描述 投票:1回答:1

[在使用PyInstaller时,包括python软件包时遇到麻烦,尤其是docxcompose。这是一个软件包,需要在PyInstaller目录中导入其site-package文件夹。我已经安装了docxcompose的pip,它位于我的站点包库中,文件夹标记为docxcomposeimport docxcompose在我在PyInstaller中引用的python文件中明确列出。

我正在使用规格文件和--onedir方法进行调试,因为我最终希望使用--onefile进行安装。到目前为止,我已经将这些添加到spec文件的分析部分,但没有运气:

hiddenimports=['docxcompose']
pathex=['C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\site-packages']

是否有没有在我的PyInstall中添加docxcompose的原因?是否可以通过其他方式强制在安装过程中将该文件夹复制到其中?

python pyinstaller docx
1个回答
1
投票

要“手动”添加docxcompose文件夹而不是依靠PyInstaller搜索,我发现您必须在spec文件的“分析”部分的“数据”中添加docxcompose的站点软件包文件夹目标。查看文字/规格文件:

sample.spec

# -*- mode: python ; coding: utf-8 -*-

import sys
from os import path
site_packages = next(p for p in sys.path if 'site-packages' in p)
block_cipher = None


a = Analysis(['ape_proposal_generator.py'],
             pathex=['C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python37\\Lib', 'C:\\MyPythonFileDest'],
             binaries=[],
             datas=[(path.join(site_packages,"docxcompose"),
"docxcompose")],
             hiddenimports=['docxcompose'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='mypythonfilename',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='mypythonfilename')
© www.soinside.com 2019 - 2024. All rights reserved.