I have inherited a project that has code in a package that has imports that are assuming code in that package are in the root directory.
For example, given this directory structure
my_project
mod_1
mod_2
- folder1
mod_3
mod_4
- folder2
mod_5
mod_5 would have an import like:
import mod_3
import mod_4
When I try to run this code I get the error that mod_1 cannot be found.
If I change the imports to this everything seems to work
import folder1.mod_3
import folder1.mod_4
However, this is not a viable solution as this is part of a long running opensource project and clearly this is not the intent of the original authors and clearly something that has been working for others without the above modifications.
How do I craft a virtual environment that will essentially add folder_1 directly to the path such that modules in folder_1 can be referenced as being in the root folder?
>Solution :
In Pycharm, use this flow
Select the source dir -> Right-Click -> Choose Mark Directory As -> Choose Sources Root
It will make the directory as a root and solve the import issues.