'Pycharm underlines absolute import, but it works fine
I have path server->api(folder), manage.py.
Pycharm underlines my absolute import from api.views import create_user
but it works! If i type like from server.api.views import create_user
pycharm does not underline, but it doesn't work
Solution 1:[1]
PyCharm has option called 'Mark Directory as' when you right click your specific directory in the Project tree.
Try to mark 'Server' folder as 'Sources root' and it should work fine.
Solution 2:[2]
I had this issue to for a long time and was really annoyed with the following simplified folder structure. I had to do like @token said, but couldn't get it to work. Turns out I had to mark the project
folder as sources root in PyCharm and that solved all the import issues!
??? project name
??? .gitignore
??? docker-compose.yml
??? project
??? .dockerignore
??? Dockerfile
??? app
? ??? __init__.py
? ??? main.py
? ??? models
? ??? __init__.py
??? db
? ??? Dockerfile
??? requirements.txt
```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | KMoberg |