如何将Python网站包文件夹(未包含)添加到PyInstaller规范文件中? [英] How can I add a Python site-package folder (that's not being included) to a PyInstaller spec file?

查看:60
本文介绍了如何将Python网站包文件夹(未包含)添加到PyInstaller规范文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

是否有理由不在我的PyInstall中添加docxcompose?可以在安装过程中强制复制该文件夹吗?

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?

推荐答案

要手动"添加 docxcompose 文件夹,而不是依靠PyInstaller搜索,我发现您必须添加以下站点:docx的打包文件夹目标位于spec文件分析部分内的数据"中.查看文字/规格文件:

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

这篇关于如何将Python网站包文件夹(未包含)添加到PyInstaller规范文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆