需要为smartsheet python sdk和PyInstaller创建一个钩子
好的,这里有很多信息,但这是我为这个解决方案搜索了几天的结果。我见过很多人以各种形式问这个问题,但没有很好的答案,我想我真的很快就能解决它了 我有一个功能完整的python脚本,它使用smartsheet python sdk模块,但当我将其作为与Pyinstaller捆绑的exe运行时,它会将smartsheet对象作为字符串读取,并且我无法访问任何属性。该模块有一个子文件夹“models”,其中还有一个子文件夹“enums”。我想我需要创建一个钩子来导入这些,所以我尝试创建一个钩子,但仍然没有成功。钩子是在编译时读取的,但不起作用 以下是参考资料 系统信息 所有内容都是最新的当前版本: Python 3.7 Pyinstaller 3.6 智能表格2.86 操作系统:Windows 10 迄今为止的尝试 有人在中找到了问题的解决方案,但他们没有提供解决方案,因此帮助不大。我已尝试按建议添加导入语句 这是我为smartsheet.models创建的尝试挂钩:需要为smartsheet python sdk和PyInstaller创建一个钩子,python,python-3.x,hook,pyinstaller,smartsheet-api,Python,Python 3.x,Hook,Pyinstaller,Smartsheet Api,好的,这里有很多信息,但这是我为这个解决方案搜索了几天的结果。我见过很多人以各种形式问这个问题,但没有很好的答案,我想我真的很快就能解决它了 我有一个功能完整的python脚本,它使用smartsheet python sdk模块,但当我将其作为与Pyinstaller捆绑的exe运行时,它会将smartsheet对象作为字符串读取,并且我无法访问任何属性。该模块有一个子文件夹“models”,其中还有一个子文件夹“enums”。我想我需要创建一个钩子来导入这些,所以我尝试创建一个钩子,但仍然没
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('smartsheet.models')
一些可能的原因它不起作用
我认为这与模块init文件中的信息有关,但我不确定如何处理它。主模块的init具有以下语句:
from .smartsheet import Smartsheet, fresh_operation, AbstractUserCalcBackoff # NOQA
模型子模块中的init有语句可导入目录中的各个模型:
from __future__ import absolute_import
# import models into model package
from .access_token import AccessToken
from .account import Account
from .alternate_email import AlternateEmail
from .attachment import Attachment
from .auto_number_format import AutoNumberFormat
# This continues for other models
所以我认为我需要在我的hook文件中以某种方式模仿这个model import语句,但我不知道怎么做
代码和错误消息:
它创建主smartsheet对象ok,因为它不引用任何子模块项:
# Creates a smartsheet object for an account with an api access token
ss = smartsheet.Smartsheet(a_token)
但是引用此对象中的子模块的任何操作都会失败
ss.Sheets.get_sheet(residential_id)
这是我运行程序时收到的错误消息:
ImportError! Could not load api or model class Users
# print statement I added to show the string object that is supposed to be a smartsheet object
<smartsheet.smartsheet.Smartsheet object at 0x00000292D4232408>
Exception type: AttributeError
Exception message: 'str' object has no attribute 'get_sheet'
Stack trace:
File: sum_report.py
Line: 516
Function nameName: main
Message:
File: snow_functions.py
Line: 437
Function nameName: connect_smartsheet
Message:
恐怖!无法加载api或模型类用户
#我添加的print语句用于显示假定为smartsheet对象的string对象
异常类型:AttributeError
异常消息:“str”对象没有“get\u sheet”属性
堆栈跟踪:
文件:sum_report.py
电话:516
函数名称:main
信息:
文件:snow_functions.py
电话:437
函数名称名称:connect_smartsheet
信息:
我遇到了同样的问题。我发现,您必须添加所有需要的单个模块作为隐藏导入 打开创建的.spec文件。如果以前使用过
pyinstaller script.py
,请在脚本目录中查找文件script.spec
。打开它并修改该部分:
hiddenimports=[
'smartsheet.models'
'smartsheet.sheets',
'smartsheet.search',
'smartsheet.users'
]
然后运行pyinstaller script.spec
将spec文件与隐藏的导入一起使用。请尝试再次运行您的程序包。如果脚本再次失败,您可能需要向隐藏导入数组添加其他模块(只需查看错误中引用的模块)
在添加模型、图纸和搜索之后,我终于让我的工作正常了 我遇到了同样的问题。我发现,您必须添加所有需要的单个模块作为隐藏导入 打开创建的.spec文件。如果以前使用过
pyinstaller script.py
,请在脚本目录中查找文件script.spec
。打开它并修改该部分:
hiddenimports=[
'smartsheet.models'
'smartsheet.sheets',
'smartsheet.search',
'smartsheet.users'
]
然后运行pyinstaller script.spec
将spec文件与隐藏的导入一起使用。请尝试再次运行您的程序包。如果脚本再次失败,您可能需要向隐藏导入数组添加其他模块(只需查看错误中引用的模块)
在添加模型、图纸和搜索之后,我终于让我的工作正常了