I have a python (3.6.3) project which has the following structure
setup.py
utils #python package
utils/constants.py
utils/name_reports.py
normalization #python package
normalization/resolve_name.py
categorization #python package
categorization/animal_categories.py
You can find the source code here on github - https://github.com/techmango-org/python-import-resolution
Here is the source code for utils/name_reports.py
import normalization.resolve_name as rn
import categorization.animal_categories as ac
test_name = 'DOGY'
resolved_name = rn.get_animal_name(test_name)
print('********ANIMAL CATEGORY IS:', ac.get_animal_score(resolved_name))
When I run python utils/name_reports.py
I am getting the following exception
Traceback (most recent call last):
File "utils/name_reports.py", line 1, in <module>
import normalization.resolve_name as rn
ModuleNotFoundError: No module named 'normalization'
I have tried to solve this problem by installing the current package into virtual env site packages by running pip install .
but that means for every local change I have to run pip install --upgrade .
to move my local changes into site packages.
I have been using a hack -m unittest
to get this problem solved. Check this screenshot
But I am unable to understand what difference does it create. Here are the exact questions -
- How to resolve python import issue in this situation?
- Is there a better approach to structure python code such that we do not face relative imports issue?
- What difference does
-m unittest
is creating which is solving this issue?