Python: Importing a subpackage from the subpackage above it
Currently working on an API for a project I'm working on, and have run
into a problem when trying to test it, by doing $ python Main.py at the
command line. (I am running Windows 7.)
My directory structure is something like this:
(The text after the "+" symbols are the directory names relative to the
root directory of my project.)
+ /
| > Main.py
+ - - - + /ehmrss
| > __init__.py
| > api.py
+ - - - + /ehmrss/constants
| > __init__.py
| > iotypes.py
| > opcodes.py
| > packet.py
| > serial.py
All __init__.py files are empty.
The error occurs when it tries to do an import in api.py, so I will only
show you the top of the two files.
Main.py has:
from ehmrss import api
import serial
for its imports, while api.py has:
# Module information
__author__ = "Name"
__date__ = "Date"
__version__ = "0.1a"
# Python imports
import serial
from time import sleep, time
from inspect import isfunction
#import sys
#print sys.path # This includes the project root directory, as you'd
expect.
# EHMRSS imports
from constants import opcodes, packet, serial, iotypes # Error
Which yields the error:
ImportError: No module named constants
I have also tried using:
from ehmrss.constants import opcodes, packet, serial, iotypes
but that yields the same error.
I'm guessing that I haven't understood the import system, but I can't
fathom what it is I am missing.
Perhaps that the entry point has an effect on it?
No comments:
Post a Comment