Report this

What is the reason for this report?

Deploy/ Build errors in FastAPI app.

Posted on July 16, 2022
  1. In my first attempt I left the build command blank. It seemed to build successfully, and then the deploy log showed error: ModuleNotFoundError: No module named '_tkinter' I am not even using Tkinter in my app.

  2. Second attempt I added a procfile with the line: web: uvicorn --app-dir src nft_server:app --reload in my repo and even the build failed.

My github repo: https://github.com/zubin-madon/NFTrees

To build locally this is what I do: app.py - client side web application (transpiled files get put into ./src/target/) (venv) $ transcrypt --nomin --map src/app.py nft_server.py - FastAPI REST server (venv) $ uvicorn --app-dir src nft_server:app --reload http://localhost:8000

  1. I tried this article here: https://dev.to/mrcartoonster/fastapi-do-deploy-1h10

But the run command is failing me. Here’s what the article says:

Modify the Run Command setting to point to your application. For this example, my project is named mysite. So the modified command would be gunicorn --worker-tmp-dir /dev/shm --config gunicorn.conf.py src.main:app

I replaced src.main with src.nft_server as per my repo. The rest I kept the same. Build succeeded but deploy failed.

[2022-07-16 04:34:19] bash: gunicorn: command not found
Deploy Error: Run Command Not Executable


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I’ve just forked your repo and tried to deploy it. It all worked as expected.

I can see that you’ve added the requirements.txt file just a couple of hours ago, have you tried deploying the app after the file was added?

The error that you are getting indicates that the first time you tried deploying the app you did not have the requirements.txt file in your repo.

Besides, for anyone who might come across this in the future, here are a few troubleshooting steps that might be helpful:

  1. ModuleNotFoundError: No module named ‘_tkinter’: This is a common issue faced when deploying Python applications. ‘_tkinter’ is the standard Tcl/Tk interface module for Python. The issue can arise when certain libraries have a dependency on it, even if you aren’t directly using it. To address this, you might want to:

    • Double-check your dependencies in requirements.txt to see if there’s anything that might be pulling in Tkinter.
    • If you’re sure you don’t need Tkinter, you can safely ignore this error, but remember that if a library is trying to import it, that library might not work as expected.
  2. Procfile: If you’re following the Heroku-style deployment (which DigitalOcean’s App Platform sometimes uses), the Procfile is crucial. The format and contents should be correct. Given that you mentioned web: uvicorn --app-dir src nft_server:app --reload, ensure the Procfile is at the root level of your repository and there are no typographical errors. Also, make sure there’s no additional whitespace.

  3. Use of gunicorn: If you’re trying to use gunicorn, you must ensure it’s installed and listed in your requirements.txt. If not, the deploy process won’t know about it and you’ll receive the error “gunicorn: command not found”. Add it to your requirements.txt.

  4. Additional Tips:

  • Make sure all the required dependencies for your project are listed in requirements.txt.
  • If you’re using any environment-specific configurations, make sure they’re correctly set up in DigitalOcean’s App Platform.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Dark mode is coming soon.