Python folder structure for project directory and easy import Python folder structure for project directory and easy import python-3.x python-3.x

Python folder structure for project directory and easy import


PYTHONPATH environment variable might be a way to go. Just set it to projects folder location:

PYTHONPATH=/somepath/temp_projects

and you'll be able to use util as follows:

import util.geometryutil.geometry.rotate_coordinates(....)

Also this will be recognized by PyCharm automatically.


I believe the correct route would be completely different than what you are doing right now. Each project should be stored in a different Git repository, share modules should be added as git submodules. Once those projects will get larger and more complex (and they probably will), it would be easier to manage them separately.

In short

Projects structure should be:

Project_1  |- utils <submodule>       |- storage.py       |- geometry.py  |- main.pyProject_2  |- utils <submodule>       |- storage.py       |- geometry.py  |- main.py

Working with submodules

### Adding a submodule to an existing git directorygit submodule add <git@github ...> <optional path/to/submodule>### Pulling latest version from master branch for all submodulesgit submodule update --recursive --remote### Removing submodule from project# Remove the submodule entry from .git/configgit submodule deinit -f path/to/submodule# Remove the submodule directory from the project's .git/modules directoryrm -rf .git/modules/path/to/submodule# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodulegit rm -f path/to/submodule

Further reading https://git-scm.com/book/en/v2/Git-Tools-Submodules


According to Importing files from different folder adding a __init__.py in the util folder will cause python to treat it as a package. Another thing you can do is use import util.geometry as geometry and then you could use geometry.rotate_coordinates(...) which also improves readability.