Search code examples
pythondebuggingpycharmfastapipydantic

Adding extra words to the module name when running the debugger


I started studying my first library, fastapi in python and was faced with the fact that when I try to run this code in pycharm through the debugger, I get an error that the module name, Pydantic, was specified incorrectly when importing. Moreover, he adds the name of the file, no matter how I call it, to the name of the module, exactly paydantic, through a dot and, of course, there is no such module. Well, the server doesn't start. Google and AI could only help me formulate the question correctly; I myself could not find an answer on how this could be solved. Thank you all so much in advance!

Code is simple. I am not sure that is needed, but here it is:


from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
    return {"message": "Hello World"}

Name of error is: "ModuleNotFoundError: No module named 'pydantic.main.py'; 'pydantic.main' is not a package


Solution

  • It was an error in the venv that pycharm created. I don't know what exactly it was, but I deleted it and create new and it start works well. Before that I trying this code on Visual Studio Code and it's started well so I decided to try to find some troubles in pycharm.