Understanding folder organization

Pycharm is redlining my import statements due to the way I'm organizing my folders. I'm trying to understand how I can fix it.

  • I have one folder that is called "General" where I group a collection of scripts.
  • Each script is a folder of its own. i.e. General\web_scrapping.
  • I have a folder General\common where I put utility functions that get used across my different scripts.

In Pycharm I open a "project" at the General folder level. I think I need to tell Pycharm that this a collection of "projects" and not one project. Anyone know how I can fix the redline issue in my import statements?

 

0
3 comments

Hi, 

Does it help to mark the sub-folders as source root? https://www.jetbrains.com/help/pycharm/project-structure-dialog.html#ac5dab0e

Doing this adds those folder to PYTHONPATH at runtime, and also tells PyCharm to resolve the modules starting from source roots.

0

Hi Andrey, yes it does!

So I can have one main folder to group my "mini-projects"/Python Packages and mark them as source root. Is this a common setup?

0

Well, yes, this is a correct way to do it. 

Another approach is to add them as multiple content roots in the project structure settings (https://www.jetbrains.com/help/pycharm/project-structure-dialog.html), and modify the interpreter paths manually (https://www.jetbrains.com/help/pycharm/python-interpreters.html#paths), which is more complicated.

0

Please sign in to leave a comment.