So I have a directory with three files in it. Two python files, analyze and sanity, and a shell script. I’m trying to import a class from analyze into sanity. I’m pretty sure the issue is with the fact hat sanity is being run in the shell script and not being used as a package itself but I”m not sure how to actually fix that. I’m not sure ion this adds any context to the problem but sanity is registered using invoke() for the use of gdb. Error I’m getting is
from . import sanity
ImportError: attempted relative import with no known parent package
I’ve tried various ways and currently have from . import analyze
to import the file as a module as whole.
Abhishek Vemula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
In fact, you can use
import sanity
directly if your source files are in the same directory.
If you are using Python <= 3.3
I think you can create __init__.py
in the source directory. (I haven’t tested this yet).
About init.py
An __init__.py
file has 2 functions.
- convert a folder of scripts into an importable package of modules (before Python 3.3)
- run package initialization code
More info
If you are using Python > 3.3
Perhaps the answers for this question can help you.