How can I add a Python site-package folder (that's not being included) to a PyInstaller spec file?

。_饼干妹妹 提交于 2020-01-25 06:15:29

问题


I am having trouble including a python package while using PyInstaller, particularly docxcompose . This is a package that needs to import its site-package folder within the PyInstaller directory. I have pip installed docxcompose and it is in my site-packages library, with the folder labeled as docxcompose. import docxcompose is explicitly listed in the python file I am referencing in PyInstaller.

I am debugging using a spec file and the --onedir method, as I want to eventually install using --onefile. I have added these to the analysis section of spec file so far, with no luck:

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

Is there a reason docxcompose is not being added in my PyInstall? Is there I way I can force that folder to be copied in during install otherwise?


回答1:


To "manually" add the docxcompose folder instead of relying on the PyInstaller search, I found that you have to add the site-package folder destination for docxcompose in "datas" within the analysis section of the spec file. See text/spec file:

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')


来源:https://stackoverflow.com/questions/59743234/how-can-i-add-a-python-site-package-folder-thats-not-being-included-to-a-pyin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!