Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 692
Pulldown Avatar asked Feb 11 '26 11:02

Pulldown


1 Answers

It has to be Github with lowercase h.

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

like image 96
furas Avatar answered Feb 14 '26 22:02

furas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!