Reputation: 11
I want to create a script that deploys with Streamlit in python that lists the contents of a specific repository. Is it even possible? because I'm trying it and it always says this:
ImportError: cannot import name 'Github' from 'github' (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/github/__init__.py)
Traceback:
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 564, in _run_script
exec(code, module.__dict__)
File "/Users/blanc/Desktop/My-notes/webpage.py", line 1, in <module>
from github import Github
I have literally this import that works with output in console:
from github import Github
I've checked like 18 times that I have the requeriments intalled(and the correct version of PyGithub) and I don't know what else can I do. Hope you can help me :)
This is the code I'm using:
from github import Github
def list_content_repo():
g = Github()
# github username
username = g.get_user("gitblanc")
# Obtain the repository
repo = username.get_repo("Obsidian-Notes")
print(repo.get_contents(""))
Upvotes: 0
Views: 184
Reputation: 5024
Just to let you know that I don't have issues with pygithub and streamlit.
main.py
from github import Github
import streamlit as st
def list_content_repo():
g = Github()
username = g.get_user("gitblanc")
repo = username.get_repo("Obsidian-Notes")
contents = repo.get_contents("")
st.write('#### Contents')
st.write(contents)
if __name__ == '__main__':
list_content_repo()
Try to setup your development environment this way. Let us see if you still have an issue. I am using windows 10 and use virtual environment. Open powershell.
PS C:\Users\ferdi> f:
I use drive f.
PS F:\> mkdir temp_streamlit
PS F:\> cd temp_streamlit
PS F:\temp_streamlit> python --version
Python 3.10.6
PS F:\temp_streamlit> python -m venv myvenv
PS F:\temp_streamlit> ./myvenv/scripts/activate
(myvenv) PS F:\temp_streamlit> python -m pip install pip -U
(myvenv) PS F:\temp_streamlit> pip install streamlit
(myvenv) PS F:\temp_streamlit> pip install pygithub
Create main.py using the above code and run streamlit.
(myvenv) PS F:\temp_streamlit> streamlit run main.py
You should see the same output above.
Upvotes: 1