Python is installed in a local directory.
My directory tree looks like this:
(local directory)/site-packages/toolkit/interface.py
My code is in here:
(local directory)/site-packages/toolkit/examples/mountain.py
To run the example, I write python mountain.py
, and in the code I have:
from toolkit.interface import interface
And I get the error:
Traceback (most recent call last):
File "mountain.py", line 28, in ?
from toolkit.interface import interface
ImportError: No module named toolkit.interface
I have already checked sys.path
and there I have the directory /site-packages
. Also, I have the file __init__.py.bin
in the toolkit folder to indicate to Python that this is a package. I also have a __init__.py.bin
in the examples directory.
I do not know why Python cannot find the file when it is in sys.path
. Any ideas? Can it be a permissions problem? Do I need some execution permission?
755
. That was becauseumask
on the machine was0027
due to which theothers
did not haveread
permission causing module to not be read. Addingread
permission fixed my problem. It's worth checking the permission of the target directory post-installation. – Curiointerface
(have been a conflict). – Theoretician__init__.py
hasn't been necessary since Python 3.3 for relative imports, and I can't think of a reason it would ever have been required for absolute imports. Absolutely mind-boggling that this nonsense has millions of views. – Leporidesys.path
accurately enough to be sure of understanding the problem. In particular, I can't fathom what the "local directory" might be, but that sounds unlikely to be a place that makes sense to contain thesite-packages
sub-directory.) – Leporide