0

when deploying the project on Vercel, an error occurs:

File "/var/task/api/main.py", line 2, in <module>
from config import app, db
ModuleNotFoundError: No module named 'config'

i have 3 *.py files in my api folder

|api
   |-main.py
   |-config.py
   |-models.py

main.py has imports from config.py and models.py. I added vercel.json from the example

{
  "rewrites": [
    { "source": "/(.*)", "destination": "/api/main" }
  ]
}

But I don't understand how to properly specify the path to my modules so that main.py knows how to get them

3
  • I don't know how it works in vercel but in normal system it needs to add /api to PYTHONPATH. But your error shows File /var/task/api/main.py, not File /api/main.py and maybe this is problem - maybe you should add /var/task/api or /var/task/api/main Commented Aug 24 at 20:36
  • when I look at documentation for rewrites then it looks for me like it is for rewriting ULRs used to load web pages, not for foldes/paths used by Python to import modules. Commented Aug 24 at 20:42
  • 1
    you could check what folders you have in print( sys.path ). it also allows to append some folders before importing. ie. sys.path.append( "/var/task/api" ) Commented Aug 24 at 20:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.