Netlify Build Failed - Invalid Filename Error Despite .gitignore Excluding venv Folder - Python FastAPI Project

Hello Netlify Community,

I am encountering a persistent “Invalid filename” error during the “building site” stage when trying to deploy my Python FastAPI application to Netlify. I have been troubleshooting this for days and have exhausted most standard solutions, and I am hoping someone in the Netlify community can provide assistance.

Problem Description:

  • Netlify deployment fails during the “building site” stage with the error: “Invalid filename ‘venv/lib/python3.12/site-packages/pandas/tests/io/data/legacy_pickle/1.2.4/empty_frame_v1_2_4-GH#42345.pkl’. Deployed filenames cannot contain # or ? characters”.
  • The error message indicates an “Invalid filename” within the venv/lib/python3.12/site-packages/pandas/tests/io/data/legacy_pickle/1.2.4/ directory, suggesting Netlify is trying to deploy files from my virtual environment’s site-packages folder.

Troubleshooting Steps Already Taken:

  • Added ‘venv’ to my .gitignore file in the project root directory to exclude the virtual environment folder from Git and deployment.
  • Verified that the .gitignore file is correctly placed in the root and that the ‘venv’ rule is present and not commented out.
  • Cleared the Netlify build cache multiple times and triggered new deployments.
  • Tried explicitly setting the Python version in Netlify build settings (although no direct “Python version” setting is available, I tried different “Build image” options if applicable).

Despite these troubleshooting steps, the “Invalid filename” error still persists during Netlify deployment, and the build continues to fail during the “building site” stage.

I am seeking assistance from the Netlify Community to understand:

  1. Why is Netlify still trying to deploy files from the ‘venv’ folder (specifically the problematic filename within pandas test data), even though I have ‘venv’ in my .gitignore and have cleared the build cache? It seems like .gitignore is not being effective in excluding the venv folder during Netlify deployment.
  2. Is there any Netlify-specific configuration or setting that I might be missing that is causing Netlify to include the ‘venv’ folder in the deployment bundle despite .gitignore?
  3. Are there any workarounds or alternative approaches to ensure Netlify completely ignores the ‘venv’ folder during deployment and avoid this “Invalid filename” error?
  4. Could this “Invalid filename” error be related to the Python version Netlify is using for the build (currently using the default “Ubuntu Noble 24.04” build image, which might use Python 3.13.1), and if so, how can I explicitly control or downgrade the Python version in Netlify build settings (if even possible)?

[Link to Netlify Site (Optional - Add if you are comfortable sharing)]
(You can add a link to your Netlify site here if you are comfortable sharing it with the community for debugging purposes. This is optional but might be helpful.)

[Link to GitHub Repository (Optional - Add if you are comfortable sharing)]
(You can add a link to your public GitHub repository here if you are comfortable sharing it with the community. This is also optional but might be helpful for others to examine your project structure and Netlify configuration.)

I would greatly appreciate any insights, suggestions, or troubleshooting advice from the Netlify Community to help me resolve this persistent “Invalid filename” error and get my ThinkAlike project deployed successfully on Netlify.

Thank you in advance for your time and assistance!

Sincerely,

Will

You’re likely missing setting the publish directory and thus, Netlify is attempting to publish the root of your repo. By the way, I don’t think Netlify supports a FastAPI project. You can host its documentation, not the API itself.