ModuleNotFoundError : No module named ‘networkx’

File “/usr/local/lib/python3.7/site-packages/streamlit/”, line 311, in _run_script exec(code, module.dict)

File “/Users/qinyilong/PycharmProjects/UMLS-explorer/”, line 3, in import networkx as nx

The original code runs well with python3.7 in the terminal.

I looks like you need to pip install networkx.

I have networkx installed in python 2.7, 3.6, 3.7, 3.8, but streamlit doesn’t seem to be able to find the networkx module. The script works well without streamlit.

1 Like

Hi @louixp,

Streamlit has largely been built and tested using virtual environments. Can you set up a virtual environment for your project and try again? I’m hoping that fixes the issue, but if it doesn’t, please do come back and share the traceback with us again.

Any virtual environment will do. On your OSX system, you should be able to do the following successfully:

python3.7 -m venv ~/.streamlit_ve
source ~/.streamlit_ve/bin/activate
pip install -U pip
pip install streamlit
pip install networkx

You would also install any other dependencies you need to run your script as well before running streamlit run

Let us know how that goes!

This solved the problem. Thanks!