FastAPI deployment failure: Could not parse requirements.txt on Vercel

Problem

I am trying to deploy my FastAPI project (Python) to Vercel via GitHub, however I am getting this error:

Error: could not parse requirements.txt: Failed to parse requirements file. Line 1, col 1: expected end of input

Context

The thing is that I have been able to deploy in the past and the last successful build was on Jan 6. Today, there were few issues in my project so I had to do fixes and tried to deploy again, but the build failed.

Can anyone advice on this? The requirements.txt file is not even empty and is present in my GitHub repository.

1 Like

That error usually means there’s a parsing error with the requirements.txt file. Possibly encoding issues or just an unexpected character.

Quick fix to try:

 # Recreate requirements.txt
 pip freeze > requirements.txt
 
 # Verify it's not empty
 cat requirements.txt
 
 # Commit and push
 git add requirements.txt
 git commit -m \\Fix requirements.txt\\
 git push

If that doesn’t solve it, can you share:

  • The first few lines of your requirements.txt file
  • The output of file requirements.txt command (to check encoding)
  • Whether you’re using any special characters or comments in the file

Thank you for your contribution. It still didn’t work as somehow Vercel or Github deemed my requirements.txt as empty file (?)

So, I decided to add in pyproject.toml file and added required dependencies in there instead, and now my Vercel project is able to build properly and running smoothly now.

Try creating a new requirements.txt file in notepad, then copy the content from your original requirements.txt file into the new file, then upload it into GitHub, this should resolve the error, since the error is caused because Vercel is reading two non-printable character at the start of the requirements.txt file. It worked for me.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.