Importing module item of subpackage from another subpackage
Question: I have this project structure:

    
    
    root_package/
    root_package/packA/
    root_package/packA/__init__.py (empty)
    root_package/packA/moduleA.py
    root_package/packB/__init__.py (empty)
    root_package/packB/moduleB.py
    root_package/rootModule.py
    

In the `rootModule.py` I have `from packA.moduleA import ModuleAClass`.  
At the `packA.moduleA.py` I have this `from root_package.packB.moduleB import
ModuleBItem`.

When running rootModule either via PyCharm or the terminal with `python
./rootModule.py` I am getting this error:

Was this the right way of importing?

    
    
    Traceback (most recent call last):
      File "/project_dir/rootPackage/rootModule.py", line 7, in <module>
        from packA.moduleA import ModuleAClass
      File "/project_dir/rootPackage/packA/moduleA.py", line 8, in <module>
        from rootPackage.packB.moduleB import module_b_method
      File "/project_dir/rootPackage/rootModule.py", line 7, in <module>
        from packA.wavelet_compression import WaveletCompression
    ImportError: cannot import name WaveletCompression
    

How to solve this?

**Update 1**  
I've added a test file at the _project_folder_ (**not** the root_package
folder).  
So the current directory structure is this:

    
    
    project_folder/
    project_folder/root_package/
    project_folder/root_package/packA/
    project_folder/root_package/packA/__init__.py (empty)
    project_folder/root_package/packA/moduleA.py
    project_folder/root_package/packB/__init__.py (empty)
    project_folder/root_package/packB/moduleB.py
    project_folder/root_package/rootModule.py
    project_folder/test_rootModule.py
    

I haven't made the `project_folder` a package (no `__init__.py` file) since,
the `test_rootModule` is simply a script to help me run the experiments.

So, in `root_package/packA/moduleA.py`, after changing the `from
root_package.packB.moduleB import ModuleBitem`, to `from packB.moduleB import
ModuleBitem`, as the answer suggests, it works.

But now there are **two** problems:  
1\. PyCharm doesn't agree with the change:  
[![pycharm-import-
error](http://i.stack.imgur.com/7D9Zj.png)](http://i.stack.imgur.com/7D9Zj.png)

  2. I cannot run my experiments from the `project_folder/test_rootModule.py` script. I got this error: 

Traceback (most recent call last):  
File "project_folder/test_rootModule.py", line 8, in  
from root_package.rootModule import rootModuleClass  
File "project_folder/root_package/rootModule.py", line 7, in  
from packA.moduleA import ModuleAClass  
File "project_folder/root_package/packA/moduleA.py", line 8, in  
from packB.moduleB import module_b_item  
ImportError: No module named packB.moduleB

_I cannot seem to get the 2nd Traceback to look like a code segment._

**Update 2**

What solved the problem was going to the `Project: project_name > Project
Structure` dialog in PyCharm, selecting the `root_package` and then setting it
as a `Sources` folder.  
Now, I can run via the IDE both the `rootModule` and the `test_rootModule`.

**Although** , I cannot get to run the `test_rootModule` from the terminal.
The `test_rootModule` has these imports:

    
    
    from root_package.rootModule import RootModuleClass
    from root_package.packB.moduleB import module_b_item
    

I am at the `project_folder` dir, and run `python ./test_rootModule.py` and
get this error:

    
    
    Traceback (most recent call last):
      File "./test_rootModule.py", line 8, in <module>
        from root_package.rootModule import RootModuleClass
      File "project_folder/root_package/rootModule.py", line 7, in <module>
        from packA.moduleA import ModuleAClass
      File "project_folder/root_package/packA/moduleA.py", line 8, in <module>
        from packB.moduleB import module_b_item
    ImportError: No module named packB.moduleB
    


Answer: If you are running all your code from within this path:

`project_folder`

Then you should ensure that all your modules that reside in `root_package` are
referenced by that first. So for example:

`from root_package.modA import foo`

