Import a Python library from Github Import a Python library from Github python python

Import a Python library from Github


Actually, if given package is not on PyPI (or you want a specific branch) you can still install it through pip from GitHub with:

pip install git+https://github.com/[repo owner]/[repo]@[branch name]

And for your problem it would be (although @pandita's answer is correct for normal usage case):

pip install git+https://github.com/praw-dev/praw.git

For more information check this answer.


Experimental Python module finder/loader from github, like in golang.

So, in golang we can import like:

import "github.com/parnurzeal/gorequest"

But in python we should install package by our hands:

pip install requests

And import it like:

import requests

But with this magic package and power of PEP-0302 we can do it automatically:

from github_com.kennethreitz import requestsassert requests.get('https://github.com/nvbn/import_from_github_com').status_code == 200

Installation

You should have git, Python 3.2+ and pip:

pip install import_from_github_com

Reference: https://github.com/nvbn/import_from_github_com


Just clone the files in any dir on your python path and then build the lib typically with python setup.py install from the command line.

I typically clone a libray form git in my site_libraries folder ( the folder that holds all of your pip installed packages ). From there you can pull and then build the libraries from git just like any other git repo. Having the files there is nice because all of your libs are in once place on your python path.