在 pyinstaller 中包含 google bigquery python lib

Including google bigquery python lib in pyinstaller

我有一个 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 )

提前致谢。

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

使用名为 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']
 ...

希望这对某人有所帮助。