I have written some libraries in Python for use in my project. I have stored them locally on my system and also remotely on Github. Now every time I write some code I use sys.path.append()
in the beginning to help import my libraries from the directory in my system. I was wondering that if there is anyway to import these files directly from my Github repository
The link to my repo is this - Quacpy
If you want to use a repo which has to be installed, I'm not sure how you would want to automate installation inside another python script (also what to do if the installation fails).
However, if you just want to use some methods from another file, you could download that file and then import it:
import urllib2
def download(url):
filename = url.split('/')[-1]
print 'Downloading', filename
f = urllib2.urlopen(url)
data = f.read()
f.close()
with open(filename, 'w') as myfile:
myfile.write(data)
# get repository
download('https://raw.githubusercontent.com/biryani/Quacpy/master/auxfun.py')
# try to import something from it
from auxfun import qregnorm
q = qregnorm([0, 1, 2])
print 'Success! q =', q
Maybe you could even download the whole zip, unzip it and then import the files.