Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Python script made on Mac not working on Windows

$
0
0

I made a GH script that uses python to retrieve data from Google Sheets using code from one Erik Rood. It works with a piece of json code to give authorization to the Google Sheets that sits in the same folder as the GH file. I had it working on Mac but i can’t get it to work on Windows. Here is the code:

# r: gsheets, pygsheets, pandas
#https://erikrood.com/Posts/py_gsheets.html
import pygsheets

import os
path = os.path.dirname(ghdoc.Path)

#https://discourse.mcneel.com/t/issues-installing-pandas-on-script-editor/166071/10
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
import pandas as pd
import scriptcontext as sc
from io import StringIO

#authorization
gc = sc.sticky['authorization']

naam = naam
index = 5

# Define a function to get CSV from a specific sheet tab
def get_csv_from_tab(sh, index):
    wks = sh[index]
    data = pd.DataFrame(wks.get_all_records())
    #csv_buffer = StringIO()
    return data.to_csv(sep=';', index=False)
    #return csv_buffer.getvalue()

# Open the Google spreadsheet
sh = gc.open(naam)

# Manually select the tabs by index and store their CSVs in separate variables
Sheet1 = get_csv_from_tab(sh, 6)
Sheet2 = get_csv_from_tab(sh, 2)
Sheet3 = get_csv_from_tab(sh, 3)
Sheet4 = get_csv_from_tab(sh, 4)
Sheet5 = get_csv_from_tab(sh, 7)

Are there some obvious mistakes or common pitfalls that explain why it won’t work on Windows? I believe the error i was getting was that pygsheets wasn’t installed. Would that perhaps solve it? If so what is a sure way to do that? The windows comp is somewhere else and i would prefer to avoid a lot of trial and error. Just downloading the pygsheets package and putting it in the correct folder seemed easiest, but i couldn’t find the folder…

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles