Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm: Marking a folder as 'sources root' is not recursive for subfolders

I've followed pycharm documentation to set up the IDE to resolve imports. However it seems that each folder containing *.py files needs to be explicitly added as 'sources root' in order for the IDE to resolve all references. Can this be done recursively from a root folder?

Is this the correct way to get the IDE to resolve all codebase references, or have I not set up my project structure correctly?

I have already followed other methods for resolving references in the IDE here and here but to no avail. It seems that the IDE will only resolve them if I manually add each folder as a 'sources root'. Without the recursive functionality, large codebases will be laborious when setting up the IDE!

like image 660
rnoodle Avatar asked Feb 07 '17 16:02

rnoodle


1 Answers

If you have not used __init__.py, you should add it in each sub-directory to mark it as a package. By adding it, Python will treat the directories as containing packages making you modules visible to other directories and therefore able to be imported.

like image 118
afxentios Avatar answered Oct 19 '22 23:10

afxentios