My project has been getting bigger and the correct modules are failing to import properly. Result is the program stops running at the first line. Here is what my directory map currently looks like:
PROTOTYPE
- Sound_editor (folder)
- - openant (cloned library from Github)
- - - __init__.py
- - - (a bunch of files and folders from the library)
**
- - - ant
- - - - base
- - - - - ant.py
- - - - - __init__.py
- - - - easy
- - - - - __init__.py
- - - - - node.py
**
- - - demo.py
- - __init__.py
- - editor.py
- - reader.py
- - streamer.py
- - main2.py
- main1.py
The problem that I am getting repeatedly, in many different forms is this:
streamer.py
from editor import A_class
main1.py
import Sound_editor.streamer
When I run main1.py, it first imports streamer file. Then the streamer file attempts and fails to import the editor file. error
ModuleNotFoundError: No module named 'editor'
I don't know what else to do. I've tried:
- So many things from this guide: https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html
- variations of dotting my way to the right path:
import PROTOTYPE.Sound_editor.editor
- using from:
from Sound_editor import editor
as well asfrom Sound_editor.editor import A_class
- I've studied this answer: Importing files from different folder. I'm not sure what he means by structuring directories as a package. I have already added init.py files. (They are empty..)
What else should I try. Do you experts see any obvious errors?
Update 1
chepner recommends a relative import. from .editor import A_class
. This was successful but caused another problem that requires expounding.
streamer.py also has the following import: from .openant.ant.easy.node import Node
but also node has imports too:
node.py
from ant.base.ant import Ant
error
ModuleNotFoundError: No module named 'ant.base'
On first glance, it seems like the library I cloned from Github has some naming troubles. Folders and files with same names just sounds like a disaster. When I try using a dot here:
```from .ant.base.ant import Ant``
error
ModuleNotFoundError: No module named 'Sound_editor.openant.ant.easy.ant'
Either:
from .ant...
is not going up enough directories or- The file/folder called ant is confusing the command...??