Our projects are usually structured:
/project-name /src /django-project-name etc.. readme.md requirements.txt
If I open /project-name
instead of /django-project-name
PyCharm underlines my imports saying they can't find and it tries to reference imports as src.django-project-name.app_name.models.Thing
which can't actually be found when you run Django.
How can I get it to work the same as when I mount /djang-project-name
where it gets these things right?
Press Ctrl+Alt+S to open the IDE settings and select Appearance & Behavior | Path Variables. and enter the name of the new variable (for example, DATA_PATH ) and its value that points to the target directory with the data file on your disk. Share the run/debug configuration through your version control system.
Open the Project Structure settings. In the Projects pane of the Project Structure page, click the project you want to configure content roots for. In the dialog that opens, locate the desired directory and click OK.
In mac's PyCharm this can be done by right clicking on the src/ folder > Mark Directory as > Sources Root. Helped me with lot of similar import issues. Hope this helps someone.
Source roots (or source folders; shown as ). These roots contain the actual source files and resources. PyCharm uses the source roots as the starting point for resolving imports. The files under the source roots are interpreted according to their type.
I fixed it by going to File -> Preferences -> Project Structure
selecting the /django-project-name
in the tree and clicking sources
to add it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With