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

寵の児 提交于 2020-01-14 11:32:02

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/42094723/pycharm-marking-a-folder-as-sources-root-is-not-recursive-for-subfolders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!