I am writing a python module neuralnet. It was working all fine in Python2, but in Python3, imports are failing.
This is my code structure.
neuralnet/
__init__.py
train.py # A wrapper to train (does not define new things)
neuralnet.py # Defines the workhorse class neuralnet
layers/
__init__.py
inlayer.py # Defines input layer class
hiddenlayer.py
application/ # A seperate application (not part of the package)
classify.py # Imports the neuralnet class from neuralnet.py
train.py needs to import neuralnet.py's neuralnet class.
neuralnet.py needs to import layers/inlayer.py etc.
(I prefer relative imports.)
I have a different application (classify.py) which needs to import this module. Where I do...
from neuralnet.neuralnet import neuralnet
I have tried a few ways to import. Either I get an error (mostly arcane like parent is not imported)
1) While running train.py (which is a part of the neuralnet module)
from . import layer # In file neuralnet.py
SystemError: Parent module '' not loaded, cannot perform relative import
Or
2) while running classify.py (which is outside the module).
from layer.inlayers import input_layer # In file neuralnet.py
ImportError: No module named 'layer'
My imports worked perfectly well for years in Python2. I am wondering what Python3 expects of me? Should I move train.py to outside my module (technically it is not a part of the module)? Please suggest best practice.
Thanks Rakesh