So I made this script that grabs some modules from github to use in Python. Therefore, no python packages need to be pre-installed before running the code. It works great, however, with oauth2client I seem to have some problems. It throws an error at this line: from oauth2client.service_account import ServiceAccountCredentials. If I write import oauth2client it works, but it cannot find oauth2client.service_account. If I write oauth2client.oauth2client.service_account it does find the service_account class, but then there are some imports within the class that need to happen which results in another error because of an error in the path. Any idea how to deal with this?
Thanks!
import sys
import urllib.request # python 3
import zipfile
import os
def import_module(rep_zip_url, module_directory, p=0):
filename, headers = urllib.request.urlretrieve(rep_zip_url)
zip = zipfile.ZipFile(filename)
directory = filename + '_dir'
zip.extractall(directory)
module_directory_from_zip = os.listdir(directory)[0]
os.rename(os.path.join(directory, module_directory_from_zip),
os.path.join(directory, module_directory))
sys.path.append(directory)
import_module('https://github.com/stefanpauliuk/dynamic_stock_model/archive/master.zip', 'dynamic_stock_model')
import_module('https://github.com/burnash/gspread/archive/master.zip', 'gspread')
import_module('https://github.com/google/oauth2client/archive/master.zip', 'oauth2client')
from dynamic_stock_model import DynamicStockModel
import numpy as np
import matplotlib.pyplot as plt
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('GA IN DSM-cc35f2cd944c.json', scope)