AssertionError: No project key defined while deploying Streamlit web app

I was not able to deploy my Streamlit program that executes locally without an issue. Below is the traceback for the problem:

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/", line 565, in _run_script

    exec(code, module.__dict__)

  File "/app/income-and-expenses-tracker/", line 13, in <module>

    import database as db

  File "/app/income-and-expenses-tracker/", line 10, in <module>

    deta = Deta(project_key=DETA_KEY)

  File "/home/appuser/venv/lib/python3.10/site-packages/deta/", line 33, in __init__

    project_key, project_id = _get_project_key_id(project_key, project_id)

  File "/home/appuser/venv/lib/python3.10/site-packages/deta/", line 8, in _get_project_key_id

    raise AssertionError("No project key defined")

AssertionError: No project key defined

The line of code deta = Deta(project_key=DETA_KEY) in should not has any problem in my opinion as I use a python package called python-dotenv to retrieve my private project_key that is stored in a .env file and the .env file is being hidden by including it in a .gitignore file.

Link to the GitHub repository of the project:

If the .env file is not in your github repo, how can the application know what is stored in it?

You migh want to read about secrets management in Streamlit Cloud.

Thank you very much for your reminder!!! :rofl::rofl::rofl:
I forgot that the .env file was not stored in the GitHub repository and it works when I apply your solution.