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
The first method is fairly simple: all you need to do is put your . csv file in a GitHub repository. Now, all you have to do is enter the url of your . csv file in the code.
You can deploy Git locally, or use it via a hosted service, such as Github, Gitlab or Bitbucket. One of the advantages of using pip together with Git is to install the latest commits of unreleased Python packages as branches from Github.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With