ImportError: No module named 'util'
I know there are many variations on this question, but I couldn't find it like mine. When I try to import a module illustris_python
, I get the error ImportError: No module named 'util'
The module utility is in the directory under the module snapshot.py
it needs, so I am confused as to why python sees one module but not the other. I've included the import call as well as the trace below.
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 3.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython features.
%quickref -> Quick reference.
help -> Python own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
In [1]: import illustris_python as il
Traceback (most recent call last):
File "<ipython-input-1-ff06d24b4811>", line 1, in <module>
import illustris_python as il
File "C:\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\site- packages\illustris_python\__init__.py", line 3, in <module>
from . import *
File "C:\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\site- packages\illustris_python\snapshot.py", line 6, in <module>
from util import partTypeNum
ImportError: No module named 'util'
In [2]:
source to share
Looking at the BitBucket repository , I'm pretty sure the problem is that this code is Python 2.x-only. Someone has done some cleanup work for a possible port, but there is still a lot to be done.
This particular error at the topsnapshot.py
:
from util import partTypeNum
In Python 2.6, this is a relative import (it was "deprecated" by PEP 328 , but I'm sure you don't actually get the default warning ...), so it looks at first in the same package as snapshot.py
where it finds util.py
. before browsing your sys.path
.
In Python 3.4, this is an absolute import, so it just looks in yours sys.path
(well, it calls your top-level search engines, but that usually means search in yours sys.path
) and isn't util.py
there.
If you're trying to end up porting this code example to 3.x yourself, just change it to an explicit relative import:
from .util import partTypeNum
source to share