需要为smartsheet-python-sdk和PyInstaller创建一个钩子

问题描述 投票:1回答:1

好,这里有很多信息,但这是我为此解决方案寻找几天的结果。我已经看到很多人以各种形式问这个问题,但都没有很好的答案,我想我真的很想解决它!

我有一个功能齐全的python脚本,该脚本使用smartsheet-python-sdk模块,但是当我将其作为与Pyinstaller捆绑在一起的exe运行时,它将以字符串形式读取smartsheet对象,并且我无法访问任何属性。该模块有一个名为“模型”的子文件夹,而其中的另一个子文件夹为“枚举”。我认为我需要创建一个钩子来导入这些钩子,因此我尝试建立一个钩子,但仍然没有运气。钩子在编译时被读取,但是它们没有用。

供参考,这里是smartsheet package structure

系统信息

所有内容均为最新版本:Python 3.7Pyinstaller 3.6Smartsheet 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

init

来自models子模块,具有用于导入目录中找到的各个模型的语句:
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
1个回答
0
投票

我遇到了同样的问题。我发现,您必须将所需的所有单个模块添加为隐藏导入。

© www.soinside.com 2019 - 2024. All rights reserved.