Flask app running into issue when running "fly launch"

I’m trying to deploy this app, but running into an issue. I’m able to run it locally without a problem. I’m using Windows 10.

The repo is here: gutoarraes/bot: chatbot (github.com)

Upon doing fly deploy I receive the following:

2024-05-30T20:16:31Z app[18570e1f1172d8] ewr [info]    from chatbot import get_gemini_response
2024-05-30T20:16:31Z app[18570e1f1172d8] ewr [info]  File "/code/chatbot.py", line 1, in <module>
2024-05-30T20:16:31Z app[18570e1f1172d8] ewr [info]    from dotenv import load_dotenv
2024-05-30T20:16:31Z app[18570e1f1172d8] ewr [info]ModuleNotFoundError: No module named 'dotenv'
2024-05-30T20:16:32Z app[18570e1f1172d8] ewr [info] INFO Main child exited normally with code: 2
2024-05-30T20:16:32Z app[18570e1f1172d8] ewr [info] INFO Starting clean up.
2024-05-30T20:16:32Z app[18570e1f1172d8] ewr [info][    1.357994] reboot: Restarting system
2024-05-30T20:16:32Z runner[18570e1f1172d8] ewr [info]machine did not have a restart policy, defaulting to restart
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info]2024-05-30T20:16:35.332737087 [01HZ5JAPVS865EVAGD93J951GN:main] Running Firecracker v1.7.0
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info][    0.049663] PCI: Fatal: No config space access function found
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info] INFO Starting init (commit: d772ddd9)...
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info] INFO Preparing to run: `python3 -m flask run --host=0.0.0.0 --port=8080` as root
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info] INFO [fly api proxy] listening at /.fly/api
2024-05-30T20:16:35Z app[18570e1f1172d8] ewr [info]2024/05/30 20:16:35 INFO SSH listening listen_address=[fdaa:2:a8d0:a7b:15e:ccc7:c6cf:2]:22 dns_server=[fdaa::3]:53
2024-05-30T20:16:35Z runner[18570e1f1172d8] ewr [info]Machine started in 590ms
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info] * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]Usage: python -m flask run [OPTIONS]
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]Try 'python -m flask run --help' for help.
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]Error: While importing 'app', an ImportError was raised:
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]Traceback (most recent call last):
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]  File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]    __import__(module_name)
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]  File "/code/app.py", line 2, in <module>
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]    from chatbot import get_gemini_response
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]  File "/code/chatbot.py", line 1, in <module>
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]    from dotenv import load_dotenv
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info]ModuleNotFoundError: No module named 'dotenv'
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info] INFO Main child exited normally with code: 2
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info] INFO Starting clean up.
2024-05-30T20:16:36Z app[18570e1f1172d8] ewr [info][    1.387185] reboot: Restarting system
2024-05-30T20:16:36Z runner[18570e1f1172d8] ewr [info]machine did not have a restart policy, defaulting to restart
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info]2024-05-30T20:16:37.452689680 [01HZ5JAPVS865EVAGD93J951GN:main] Running Firecracker v1.7.0
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info][    0.054051] PCI: Fatal: No config space access function found
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info] INFO Starting init (commit: d772ddd9)...
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info] INFO Preparing to run: `python3 -m flask run --host=0.0.0.0 --port=8080` as root
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info] INFO [fly api proxy] listening at /.fly/api
2024-05-30T20:16:37Z app[18570e1f1172d8] ewr [info]2024/05/30 20:16:37 INFO SSH listening listen_address=[fdaa:2:a8d0:a7b:15e:ccc7:c6cf:2]:22 dns_server=[fdaa::3]:53
2024-05-30T20:16:37Z runner[18570e1f1172d8] ewr [info]Machine started in 572ms
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info] * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]Usage: python -m flask run [OPTIONS]
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]Try 'python -m flask run --help' for help.
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]Error: While importing 'app', an ImportError was raised:
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]Traceback (most recent call last):
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]  File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]    __import__(module_name)
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]  File "/code/app.py", line 2, in <module>
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]    from chatbot import get_gemini_response
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]  File "/code/chatbot.py", line 1, in <module>
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]    from dotenv import load_dotenv
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info]ModuleNotFoundError: No module named 'dotenv'
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info] INFO Main child exited normally with code: 2
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info] INFO Starting clean up.
2024-05-30T20:16:38Z app[18570e1f1172d8] ewr [info][    1.393387] reboot: Restarting system
2024-05-30T20:16:39Z runner[18570e1f1172d8] ewr [info]machine did not have a restart policy, defaulting to restart
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info]2024-05-30T20:16:40.512569796 [01HZ5JAPVS865EVAGD93J951GN:main] Running Firecracker v1.7.0
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info][    0.047564] PCI: Fatal: No config space access function found
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info] INFO Starting init (commit: d772ddd9)...
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info] INFO Preparing to run: `python3 -m flask run --host=0.0.0.0 --port=8080` as root
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info] INFO [fly api proxy] listening at /.fly/api
2024-05-30T20:16:40Z app[18570e1f1172d8] ewr [info]2024/05/30 20:16:40 INFO SSH listening listen_address=[fdaa:2:a8d0:a7b:15e:ccc7:c6cf:2]:22 dns_server=[fdaa::3]:53
2024-05-30T20:16:40Z runner[18570e1f1172d8] ewr [info]Machine started in 545ms
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info] * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]Usage: python -m flask run [OPTIONS]
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]Try 'python -m flask run --help' for help.
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]Error: While importing 'app', an ImportError was raised:
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]Traceback (most recent call last):
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]  File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]    __import__(module_name)
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]  File "/code/app.py", line 2, in <module>
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]    from chatbot import get_gemini_response
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]  File "/code/chatbot.py", line 1, in <module>
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]    from dotenv import load_dotenv
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info]ModuleNotFoundError: No module named 'dotenv'
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info] INFO Main child exited normally with code: 2
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info] INFO Starting clean up.
2024-05-30T20:16:41Z app[18570e1f1172d8] ewr [info][    1.376424] reboot: Restarting system
2024-05-30T20:16:42Z runner[18570e1f1172d8] ewr [info]machine did not have a restart policy, defaulting to restart
2024-05-30T20:17:04Z app[18570e1f1172d8] ewr [info]2024-05-30T20:17:04.394692216 [01HZ5JAPVS865EVAGD93J951GN:main] Running Firecracker v1.7.0
2024-05-30T20:17:04Z app[18570e1f1172d8] ewr [info][    0.048518] PCI: Fatal: No config space access function found
2024-05-30T20:17:04Z app[18570e1f1172d8] ewr [info] INFO Starting init (commit: d772ddd9)...
2024-05-30T20:17:05Z app[18570e1f1172d8] ewr [info] INFO Preparing to run: `python3 -m flask run --host=0.0.0.0 --port=8080` as root
2024-05-30T20:17:05Z app[18570e1f1172d8] ewr [info] INFO [fly api proxy] listening at /.fly/api
2024-05-30T20:17:05Z app[18570e1f1172d8] ewr [info]2024/05/30 20:17:05 INFO SSH listening listen_address=[fdaa:2:a8d0:a7b:15e:ccc7:c6cf:2]:22 dns_server=[fdaa::3]:53
2024-05-30T20:17:05Z runner[18570e1f1172d8] ewr [info]Machine started in 1.418s
2024-05-30T20:17:05Z app[18570e1f1172d8] ewr [info] * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]Usage: python -m flask run [OPTIONS]
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]Try 'python -m flask run --help' for help.
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]Error: While importing 'app', an ImportError was raised:
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]Traceback (most recent call last):
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]  File "/usr/local/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]    __import__(module_name)
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]  File "/code/app.py", line 2, in <module>
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]    from chatbot import get_gemini_response
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]  File "/code/chatbot.py", line 1, in <module>
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]    from dotenv import load_dotenv
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info]ModuleNotFoundError: No module named 'dotenv'
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info] INFO Main child exited normally with code: 2
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info] INFO Starting clean up.
2024-05-30T20:17:06Z app[18570e1f1172d8] ewr [info][    2.139840] reboot: Restarting system
2024-05-30T20:17:06Z runner[18570e1f1172d8] ewr [info]machine has reached its max restart count (10)

Upon running pip install python-dotenv it says Requirement already satisfied: python-dotenv in j:\vscode projects\chatbot\bot\.venv\lib\site-packages (1.0.1).

Hi there,

python-dotenv is not in your repo’s requirements.txt, so it’s not being installed in the image thus resulting in the error you see.

It works locally because you likely did pip install python-dotenv at some point, but didn’t add it to requirements.txt or run pip freeze.

Regards,

  • Daniel