s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
2.02k stars 174 forks source link

alembic upgrade head failed: ModuleNotFoundError: No module named 'pydantic_settings' #186

Closed rcholic closed 1 year ago

rcholic commented 1 year ago

I've read issues here related to alembic migrations, but looks like the failure message I got is different, so I'd make a post for help.

In my .env file, I added my url as following (suppose my app has the prefix MYAPP with a remote postgresql server ip: 120.120.120.120):

MYAPP_sqlalchemy.url=postgresql://user1:pw1@120.120.120.120/myapp_db

Then in my local computer's terminal, when I execute the following command:

alembic upgrade head

I got errors that complain pydantic_settings not found:

File "/Users/user1/myapp/myapp/db/migrations/env.py", line 10, in <module>
    from myapp.settings import settings
  File "/Users/user1/myapp/./myapp/settings.py", line 6, in <module>
    from pydantic_settings import BaseSettings, SettingsConfigDict
ModuleNotFoundError: No module named 'pydantic_settings'

Looks like a path issue for loading pydantic_settings package. anyone has seen similar issues?

s3rius commented 1 year ago

Hello. pydantic-settings is an external package. It might be a problem with dependencies. Have you got pydantic_settings in your pyproject.toml? Have you installed all dependencies? Are you executing commands in virtual environment?

rcholic commented 1 year ago

made it work by using pyenv to set up a virtual environment for my project. Thanks