Search code examples
pythonpygithub

PyGithub - Cant import Github from github


I am working on a project that needs to interface with github and clone the repo as a way to update itself.

I am just beginning to play around with PyGithub (seems very easy to use) but I keep getting this error:

Traceback (most recent call last):
  File "c:\Users\joey\Desktop\TEST\cloning.py", line 2, in <module>
    from github import GitHub
ImportError: cannot import name 'GitHub' from 'github' (C:\Users\joey\AppData\Local\Programs\Python\Python39\lib\site-packages\github\__init__.py)

Things I have already tried:

installing to the path with

pip install --target=C:\Users\joeya\AppData\Local\Programs\Python\Python39\lib\site-packages pygithub

I tried python -m pip install pygithub

I followed almost everything I could after googling my error code and yet still I am not able to run this example from the documentation:

from github import GitHub

def main():
    g = GitHub('MY TOKEN')
    for repo in g.get_user().get_repos():
        print(repo.name)
        repo.edit(has_wiki=False)
    # to see all the available attributes and methods
    print(dir(repo))

if __name__ == '__main__':
    main()

I am sure it is a simple fix but I have run out of ideas. python -V - Python 3.9.5 pip -V - pip 21.2.1


Solution

  • It has to be Github with lowercase h.

    You can see it even in examples in documentation or on PyPi.org