I just finished by basic learning of Python and I was trying to build something of my own.
I am making use of PyGithub and this is my source code, picked from here:
#!/usr/bin/python
import getpass
import sys
sys.path.append("./PyGithub");
from github import Github
from github import GithubException
username = raw_input("Github Username:")
pw = getpass.getpass()
g = Github(username, pw)
for repo in g.get_user().get_repos():
print (repo.name)
But this is giving me error :
Traceback (most recent call last):
File "test.py", line 15, in <module>
from github import Github
File "./PyGithub/github/__init__.py", line 37, in <module>
from MainClass import Github, GithubIntegration
ModuleNotFoundError: No module named 'MainClass'
Can someone please explain in brief how Python interpreter is searching for the files and how can I resolve this error. Or a good link will be appreciated. I referred this article on __init__.py
and it helped me a bit.
EDIT 1 Reference : How to fix "ImportError: No module named ..." error in Python?
After doing the following, my problem goes away....
~/Desktop/Dev/GithubMetrics/PyGithub/github $ export PYTHONPATH=`pwd`
I understand how it worked, but IMO this is not a proper solution, as I won't be doing this for every subdirectory for any module I decide to use. They are supposed to be standalone and adding the parent to the Python path should be all.
EDIT 2
Also I found that its working for only Python 2 with above version. With Python 3 its giving the error ImportError: No module named 'httplib'
. This is strange because the same library installed with pip3 does not give the error. Unless the maintainers of that library have really messed up, the source code should be same on both the Github and Python packages repository.
OK. I did pip3 install
again and went to the installed location and did a meld. The code actually differs. So this portion (EDIT2) is out of scope of this question.