2

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

Pulldown
  • 65
  • 1
  • 6
  • error shows you path to source code - so open this file and see if it has `GitHub`. Maybe you installed wrong module. Or maybe it uses different name - ie. lowercase `github` – furas Jul 26 '21 at 15:38
  • or maybe it needs program `git` to work correctly. – furas Jul 26 '21 at 15:41

1 Answers1

3

It has to be Github with lowercase h.

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

furas
  • 134,197
  • 12
  • 106
  • 148
  • OH... MY... GOD... i knew it would be something simple and I swear I looked at that. This is what I get for not just copy pasting the example lol. Thanks man – Pulldown Jul 26 '21 at 19:13
  • I never used this module but If I would have to write this code then I would automatically use `GitHub`. Frankly I should write this explanation as comment because it is only small typo. – furas Jul 26 '21 at 19:19
  • I was getting the same kind of error but this time using the correct name, with a lowercase `h`: (1) `from github import Github` (2) `ImportError: cannot import name 'Github' from 'github' (c:\dropboxs\abu\Dropbox\python\github.py)` (3) Solution: don't call your own script `github.py` to avoid conflicts with PyGithub library files https://github.com/PyGithub/PyGithub/issues/472#issuecomment-253235836 – abu Oct 29 '21 at 18:57
  • @abu it is common problem when beginners start use some module - they use the same name for script. ie. someone learn to create game using module `pygame` and he puts code in script `pygame.py`, etc. – furas Oct 30 '21 at 08:53