Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import a Python library from Github

I'm new to Python so this may sound silly.

I want to use a Python library I've found on Github, lets say on https://github.com/praw-dev/praw, and I want to be able to do git pull in the future to pull the latest commits.

Question: Should I git clone <git url> in the project directory and delete everything except the praw directory, then in my python script do a import praw?

In iPython,

import praw 

gives the error ImportError: No module named praw

Directory Structure

~\myProject\     praw\     myNotebook.ipynb 
like image 880
Nyxynyx Avatar asked Nov 13 '13 00:11

Nyxynyx


People also ask

How do I run a Python library from GitHub?

To install Python package from github, you need to clone that repository. pip install . from the locally cloned repo dir will work too.

How do I download a library from GitHub?

To download from GitHub, you should navigate to the top level of the project (SDN in this case) and then a green "Code" download button will be visible on the right. Choose the Download ZIP option from the Code pull-down menu. That ZIP file will contain the entire repository content, including the area you wanted.


2 Answers

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.

like image 59
pkowalczyk Avatar answered Oct 02 '22 04:10

pkowalczyk


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 requests  assert 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

like image 24
Mohammad Ali Avatar answered Oct 02 '22 05:10

Mohammad Ali