Skip to main content
 首页 » 编程设计

python之在 pyinstaller 中包含 google bigquery python lib

2024年10月01日6虾米姐

我有一个 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 的 Hook 文件,其中包含:

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

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

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

希望这对某人有帮助。