簡體   English   中英

如何將 Python 站點包文件夾(未包含在內)添加到 PyInstaller 規范文件?

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

我在使用 PyInstaller 時遇到問題,包括 python package,尤其是docxcompose 這是一個 package,需要在 PyInstaller 目錄中導入其站點包文件夾。 我安裝了 pip docxcompose,它在我的站點包庫中,文件夾標記為docxcompose import docxcompose明確列在我在 PyInstaller 中引用的 python 文件中。

我正在使用 spec 文件和 --onedir 方法進行調試,因為我想最終使用 --onefile 進行安裝。 到目前為止,我已經將這些添加到規范文件的分析部分,但沒有成功:

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

我的 PyInstall 中沒有添加 docxcompose 是有原因的嗎? 有什么辦法可以強制在安裝過程中復制該文件夾嗎?

或者,您可以將--collect-data "docxcompose"添加到 pyinstaller 的命令行參數中。

pyinstaller --collect-data "docxcompose"

要“手動”添加docxcompose文件夾而不是依賴 PyInstaller 搜索,我發現您必須在規范文件的分析部分的“數據”中為 docxcompose 添加站點包文件夾目標。 請參閱文本/規范文件:

樣本.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM