How to import python file located in same subdirectory in a pycharm project
Question: I have an input error in pycharm when debugging and running.

My project structure is rooted properly, `etc./HW3/.` so that `HW3` is the
root directory.

I have a subfolder in HW3, `util`, and a file, `util/util.py`. I have another
file in `util` called `run_tests.py`.

In `run_tests.py`, I have the following import structure,

    
    
    from util.util import my_functions, etc.
    

This yields an input error, `from util.util import
load_dataset,proportionate_sample ImportError: No module named 'util.util';
'util' is not a package`

* * *

However, in the exact same project, in another directory (same level as
`util`) called `data`, I have a file `data/data_prep.py`, which also imports
functions from `util/util.py` using a similar import statement...and it runs
without any problems.

* * *

Obviously, I am doing this as a homework, so I'm not that experienced...but
I've done this exact configuration for the last 3 homeworks and ran into zero
problems, so I have no idea how to even troubleshoot this problem--especially
when the other file works.

* * *

The problem goes away when I move the file to another directory. So I guess
this question is **How do I import a python file located in the same directory
in a pycharm project?** Because pycharm raises an error if I just do `import
util` and prompts me to use the full name from the root.


Answer: If you don't have an `__init__.py` create one and add this line

    
    
    from util.util import my_function
    

then you can easily import the module in your scripts the `__init__.py` tells
python that it should treat that folder as a python package, it can also be
used to import/load modules too.

in most cases the `__init__.py` is empty.

Quoting the docs

> The **init**.py files are required to make Python treat the directories as
> containing packages; this is done to prevent directories with a common name,
> such as string, from unintentionally hiding valid modules that occur later
> on the module search path. In the simplest case, **init**.py can just be an
> empty file, but it can also execute initialization code for the package or
> set the **all** variable, described later.

