[英]How can I add a Python site-package folder (that's not being included) to a PyInstaller spec file?
I am having trouble including a python package while using PyInstaller, particularly docxcompose
.我在使用 PyInstaller 时遇到问题,包括 python package,尤其是
docxcompose
。 This is a package that needs to import its site-package folder within the PyInstaller directory.这是一个 package,需要在 PyInstaller 目录中导入其站点包文件夹。 I have pip installed docxcompose and it is in my site-packages library, with the folder labeled as
docxcompose
.我安装了 pip docxcompose,它在我的站点包库中,文件夹标记为
docxcompose
。 import docxcompose
is explicitly listed in the python file I am referencing in PyInstaller. import docxcompose
明确列在我在 PyInstaller 中引用的 python 文件中。
I am debugging using a spec file and the --onedir method, as I want to eventually install using --onefile.我正在使用 spec 文件和 --onedir 方法进行调试,因为我想最终使用 --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?我的 PyInstall 中没有添加 docxcompose 是有原因的吗? Is there I way I can force that folder to be copied in during install otherwise?
有什么办法可以强制在安装过程中复制该文件夹吗?
Alternatively, you can add --collect-data "docxcompose"
to your command line argument for pyinstaller.或者,您可以将
--collect-data "docxcompose"
添加到 pyinstaller 的命令行参数中。
pyinstaller --collect-data "docxcompose"
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.要“手动”添加
docxcompose
文件夹而不是依赖 PyInstaller 搜索,我发现您必须在规范文件的分析部分的“数据”中为 docxcompose 添加站点包文件夹目标。 See text/spec file:请参阅文本/规范文件:
sample.spec样本.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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.