Nuke access google sheet API - python gspread

Hello,

I am a beginner of python coding.
I would like to use python gspread in Nuke (with oauth2client as crediential).

What I did:
I copied the 4 folders:
C:\Program Files\Python37\Lib\site-packages\oauth2client
C:\Program Files\Python37\Lib\site-packages\oauth2client-4.1.3.dist-info
C:\Program Files\Python37\Lib\site-packages\gspread
C:\Program Files\Python37\Lib\site-packages\gspread-3.1.0.dist-info
TO:
C:\Program Files\Nuke11.3v3\pythonextensions\site-packages

Then, in Nuke script editor, I try:
import oauth2client

The result is no error, I assume I successfully imported.

when I try:
import gspread
Fail and the feedback is:

Result: Traceback (most recent call last):

File “”, line 1, in
File “C:\Program Files\Nuke11.3v3\pythonextensions\site-packages\gspread_init_.py”, line 16, in
from .client import Client
File “C:\Program Files\Nuke11.3v3\pythonextensions\site-packages\gspread\client.py”, line 12, in
import requests
ImportError: No module named requests

Is there anyone know-how and share with me how to do so? And what I missed?

(The workaround for now is, complied the script that use gspread to an .exe file. Then use .py in nuke to os.system() to call the .exe and with a lot of sys.argu coding. I know it is a stupid way, but it at least working.)

Thank you.

Hey @bestchild,

Have you tried using pip to install gspread and oauth2 - it may be doing additional hooks (additional package installs, registry settings etc) than just coping the folder to your lib/site folder - on both site it describes it being the process to follow:

Also i’m assuming you have a authorization token issued to you, to pull/push data:

https://gspread.readthedocs.io/en/latest/oauth2.html

Edit:

Additional oauth2python has been deprecated by the looks of it and is not recommended - oauthlib is recommended:

This project is not maintained anymore. If you are looking for a OAuth 2.0 library to integrate into your Python application, I recommend oauthlib.

Which you should also probably install via pip or easy_install.

If nuke doesn’t pull from base/ site_packages, you may need to add it - i dont know if nuke has its own python interpreter (like mayapy) that you could bind to a IDE and install from there directly. By the looks of it you can edit your nuke init file/append sys.path to include other site packages:

1 Like

Hello, chalk,

First of all, thank you for taking time to help.

by this hint:

import sys
sys.path.append('/usr/local/python2.6/lib/python2.6/site-packages')

I can successfully import gspread in Foundry Nuke. And you are right, no copying is needed.

But now I am facing another problem:
==My code==
import sys
sys.path.append(‘C:\Program Files\Python37\Lib\site-packages’)
import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = [‘https://www.googleapis.com/auth/drive’]
credPath = “N:\BigKeeper\py\googleAPI\ServiceAccountKey” # <— change to the path you store the .json
credFile = “PUBLIC_bpproject-250415-8630f93e84d1.json”
credPath = credPath.replace("\", “/”)
credFull = credPath + “/” + credFile
Credentials = ServiceAccountCredentials.from_json_keyfile_name(credFull, scope)

client = gspread.authorize(Credentials)
sprdSht = client.open(“bpPythonA”)
sheet = sprdSht.worksheet(“crycry”)

#read the entire sheet and print out for testing
allData = sheet.get_all_records() # Get a list of all records
print(allData)

#write something to cell A1 for testing
targetCellRow = 1
targeCellCol = 1
sheet.update_cell(targetCellRow, targeCellCol, “RENDERING”)
==My code==

running in PyScripter IDE is fine.
But running in Foundy Nuke,
it can import oauth2client without error message. But it can’t recognize “oauth2client.service_account”
Anyway, I will put some effort myself for a period first.

And thank you let me know oauth2client is fading out, I will try oauthlib. The reason I use the oauth2client , is becoz of youtube clip where I learn from. :slight_smile:

Thank you.