【问题标题】:Unable to run exe file created by pyinstaller, showing error "google-api-python-client was not found"无法运行 pyinstaller 创建的 exe 文件,显示错误“google-api-python-client was not found”
【发布时间】:2021-05-23 11:48:22
【问题描述】:

我正在尝试将 python 脚本转换为使用 keys.json 文件运行的 .exe。 当我尝试运行 .exe 文件时出现错误,并且窗口会在 1-2 秒内自动关闭。

我完全迷失了,我尝试了一些互联网上可用的解决方案,但没有任何效果,我很沮丧。

我的 .spec 文件看起来像,

    # -*- mode: python ; coding: utf-8 -*-

    block_cipher = None


    a = Analysis(['SMIDST.py'],
                 pathex=['D:\\code\\SBF Interns APP\\SMIDST'],
                 binaries=[],
                 datas=[('keys.json', '.')],
                 hiddenimports=['pkg_resources.py2_warn', 'googleapiclient', 'apiclient'],
                 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,
              a.binaries,
              a.zipfiles,
              a.datas,
              [],
              name='SMIDST',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True )

请帮帮我,提前谢谢!!!

【问题讨论】:

  • 从命令行运行您的 exe - 您是否收到错误消息?
  • 是的,我收到了这个错误,Traceback (most recent call last): File "SMIDST.py", line 34, in <module> File "google\oauth2\service_account.py", line 233, in from_service_account_file File "google\auth\_service_account_info.py", line 72, in from_filename FileNotFoundError: [Errno 2] No such file or directory: 'keys.json' [16880] Failed to execute script SMIDST
  • 我已经在主文件夹和 dist 文件夹中有 keys.json 文件,我也复制了 google-api-python-client 文件夹,但没有任何效果。

标签: python pyinstaller exe google-api-python-client


【解决方案1】:

您可以更改文件读取功能以手动嵌入文件吗?如果它有效,它可能无法找到该文件。要解决这个问题,您可以尝试将 exe 复制到您的主要功能或命令行运行时所在的位置(密码路径)?

【讨论】:

  • 感谢您的回答,但我对编程很陌生,因此无法理解您的意思。可以简化一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-22
  • 2020-08-07
  • 1970-01-01
  • 1970-01-01
  • 2021-02-18
相关资源
最近更新 更多