Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to debug inside pycharm ? #517

Open
masoodkamyab opened this issue May 25, 2023 · 3 comments
Open

How to debug inside pycharm ? #517

masoodkamyab opened this issue May 25, 2023 · 3 comments

Comments

@masoodkamyab
Copy link

Hi to every one,
I want to debug with PyCharm debugger run my tests and see all variables and traces. but it seems it didn't load the .env file so I have an error that some critical environment variable is missing (note that I don't want to use docker to run my tests).
here some error that I got:

ImportError while loading conftest '/home/has/project/backend/app/app/tests/conftest.py'.
../conftest.py:7: in <module>
    from app.core.config import settings
../../core/config.py:90: in <module>
    settings = Settings()
pydantic/env_settings.py:39: in pydantic.env_settings.BaseSettings.__init__
    ???
pydantic/main.py:341: in pydantic.main.BaseModel.__init__
    ???
E   pydantic.error_wrappers.ValidationError: 11 validation errors for Settings
E   SERVER_NAME
E     field required (type=value_error.missing)
E   SERVER_HOST
E     field required (type=value_error.missing)
E   PROJECT_NAME
E     field required (type=value_error.missing)
E   SENTRY_DSN
E     object of type 'NoneType' has no len() (type=type_error)
E   POSTGRES_SERVER
E     field required (type=value_error.missing)
E   POSTGRES_USER
E     field required (type=value_error.missing)
E   POSTGRES_PASSWORD
E     field required (type=value_error.missing)
E   POSTGRES_DB
E     field required (type=value_error.missing)
E   SQLALCHEMY_DATABASE_URI
E     can only concatenate str (not "NoneType") to str (type=type_error)
E   FIRST_SUPERUSER
E     field required (type=value_error.missing)
E   FIRST_SUPERUSER_PASSWORD
E     field required (type=value_error.missing)

If anybody can help me I will appreciate it.
thanks

@MaxwellEdisons
Copy link

I also have this problem, this framework is currently unfriendly to collaborative development, everyone should not run a docker for development

@SpoonOfDoom
Copy link

You can use the EnvFile plugin so that you can explicitly tell PyCharm to load an env file in a run configuration. Very useful.
https://plugins.jetbrains.com/plugin/7861-envfile

@davidhuser
Copy link

I got it working like this (using PyCharm Professional 2024.1.3 )

Docker Connection

  • Navigate to PyCharm Settings > Build, Execution, Deployment > Docker
  • Verify connection to a running Docker Engine

Project Interpreter Setup

  • Go to PyCharm Settings > Project: your-project > Project Interpreter
    • Add new interpreter:
    • Select "On Docker Compose..."
    • Choose the verified Docker server
    • Select your fastapi service
    • Click next, ignore any errors
    • Choose "System Interpreter" (/usr/local/bin/python3)

Run Configuration

  • Create a new "FastAPI" configuration
  • Settings:
    • Application file: main.py
    • Uvicorn options: --reload --host 0.0.0.0 --port YOUR_PORT
    • Python interpreter: Remote Python 3.xx Docker Compose (your fastapi service)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants