【问题标题】:Including google bigquery python lib in pyinstaller在 pyinstaller 中包含 google bigquery python lib
【发布时间】:2017-07-17 17:05:33
【问题描述】:

我有一个 python 脚本,开头如下:

from google.cloud import bigquery

此软件包安装有:

pip install google-cloud-bigquery --upgrade

我的印象是 pyinstaller 应该找到所有必需的包并安装它们,但是当我在 windows 上运行创建的 .exe 或在 mac 上运行时,我收到错误消息:

pkg_resources.DistributionNotFound: The 'google-cloud-core' distribution was not found and is required by the application

这是我的 .spec 文件,请告诉我可以将 google-cloud-core 放在哪里,以便安装正确的软件包。

# -*- mode: python -*-

block_cipher = None


a = Analysis(['tests.py'],
         pathex=['/Users/daniellee/Development/alice-connectors/aconn'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      name='tests',
      debug=False,
      strip=False,
      upx=True,
      console=True )

提前致谢。

【问题讨论】:

    标签: python python-3.x exe pyinstaller


    【解决方案1】:

    所以这就是我让它工作的方式。

    使用名为hook-google.cloud.bigquery 的挂钩文件,其中包含:

    from PyInstaller.utils.hooks import copy_metadata
    
    datas = copy_metadata('google-cloud-bigquery')
    datas += copy_metadata('google-cloud-core')
    

    然后将此挂钩文件的路径添加到您的 .spec 文件中。

     ...
     hookspath=['/Users/joesoap/Development/project/hooks']
     ...
    

    希望这对某人有所帮助。

    【讨论】:

    • 绝对英雄。不错的一个
    • 我还发现hook文件也必须以.py后缀结尾才能被拾取。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多