【发布时间】:2020-02-07 03:28:51
【问题描述】:
好的,这里有很多信息,但这是我为这个解决方案寻找几天的结果。我见过很多人以各种形式提出这个问题,但没有好的答案,我想我真的很接近解决它了!
我有一个使用 smartsheet-python-sdk 模块的功能齐全的 python 脚本,但是当我将它作为与 Pyinstaller 捆绑的 exe 运行时,它会将 smartsheet 对象作为字符串读取,我无法访问任何属性。该模块有一个名为“models”的子文件夹和另一个名为“enums”的子文件夹。我想我需要创建一个挂钩来导入这些,所以我尝试构建一个,但仍然没有运气。编译时读取了这些钩子,但它们不起作用。
这里的参考是smartsheet package structure。
系统信息
一切都是最新的当前版本: 蟒蛇 3.7 安装程序 3.6 智能表 2.86
操作系统:Windows 10
目前的尝试
有人在this post 中找到了该问题的解决方案,但他们没有提供解决方案,因此帮助不大。我尝试按照here 的建议添加导入语句
这是我为 smartsheet.models 创建的尝试钩子:
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('smartsheet.models')
一些可能的原因它不工作
我认为这与模块 init 文件中的信息有关,但我不知道如何处理它。主模块的 init 有这样的语句:
from .smartsheet import Smartsheet, fresh_operation, AbstractUserCalcBackoff # NOQA
models 子模块中的 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
所以我认为我需要在我的钩子文件中以某种方式模仿这个模型导入语句,但我不知道该怎么做。
代码和错误信息:
它可以创建主智能表对象,因为它不引用任何子模块项:
# 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:
【问题讨论】:
标签: python python-3.x hook pyinstaller smartsheet-api