Python исполняемый файл с pyinstaller ничего не делает - PullRequest
0 голосов
/ 17 июня 2020

У меня есть сценарий в python для обновления некоторых ячеек в таблицах Google. Если я запускаю его в коде Visual Studio, он работает отлично, но я хочу сделать exe, чтобы он автоматически запускал скрипт и легко его использовал. Проблема в том, что я сделал exe с помощью pyinstaller. Я открыл его, и файл открывается через 1 секунду, он снова закрывается, и в таблицах Google ничего не происходит. В чем может быть проблема?

это код скрипта

from smart_sensor_client.smart_sensor_client import SmartSensorClient
import json
import requests
import pkg_resources.py2_warn
DEFAULT_SETTINGS_FILE = 'settings.yaml'
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.\
    from_json_keyfile_name('Smartsensors-02d98c39eaac.json',scope)
client=gspread.authorize(credentials)
sheet = client.open('tutorial1').sheet1


def run_task(settings_file=DEFAULT_SETTINGS_FILE) -> bool:

    # Create the client instance
    client = SmartSensorClient(settings_file=settings_file)

    # Authenticate
    if not client.authenticate():
        print('Authentication FAILED')
        return False

    # Get list of plants
    plants = client.get_plant_list()

    # Iterate the plant list and print all assets therein
    for plant in plants:

        # Get list of assets
        response = client.get_asset_list(organization_id=client.organization_id)
        if len(response) == 0:
            print('No assets in this plant')  
        else:

            nombre=[]
            for asset in response:
                nombre.append(asset['assetName'])
            lastsynctime=[]
            for asset in response:
                lastsynctime.append(asset['lastSyncTimeStamp'])
            sensorid=[]
            for asset in response:
                sensorid.append(asset['sensorIdentifier'])
            tiposubscripcion=[]
            for asset in response:
                asset_data = client.asset_get_asset_by_id(asset_id=asset['assetID'])
                tiposubscripcion=[].append(asset_data['sensor']['subscription']['subscriptionLevel']['description'])
            finsubscripcion=[]
            for asset in response:
                asset_data = client.asset_get_asset_by_id(asset_id=asset['assetID'])
                finsubscripcion.append(asset_data['sensor']['subscription']['endDate'])
            info=[nombre,sensorid,lastsynctime,tiposubscripcion,finsubscripcion]
            sheet.update('A1', info)

    return True


if __name__ == '__main__':

    result = run_task()

    if result is True:
        print('Task SUCCESS')
    else:
        print('Task FAILED')
...