Cannot import odl.contrib.tensorflow
sbanert opened this issue · comments
I tried to reproduce #1451, but I got the following error (on two different machines, so I hope that I did not get my configuration wrong).
Traceback (most recent call last):
File "test.py", line 2, in <module>
import odl
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/__init__.py", line 47, in <module>
from .set import *
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/set/__init__.py", line 15, in <module>
from .sets import *
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/set/sets.py", line 17, in <module>
from odl.util import is_int_dtype, is_real_dtype, is_numeric_dtype, unique
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/util/__init__.py", line 15, in <module>
from .testutils import *
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/util/testutils.py", line 13, in <module>
from future.moves.itertools import zip_longest
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/future/moves/__init__.py", line 8, in <module>
import_top_level_modules()
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/future/standard_library/__init__.py", line 813, in import_top_level_modules
__import__(m)
File "/home/banert/test.py", line 3, in <module>
import odl.contrib.tensorflow
File "/home/banert/miniconda3/envs/bug/lib/python3.6/site-packages/odl/contrib/tensorflow/__init__.py", line 17, in <module>
__all__ += layer.__all__
NameError: name 'layer' is not defined
I am using the conda environment as suggested in #1451. The output of conda list
is the following:
# packages in environment at /home/banert/miniconda3/envs/bug:
#
# Name Version Build Channel
_tflow_select 2.3.0 mkl anaconda
absl-py 0.7.0 py36_0 anaconda
astor 0.7.1 py36_0 anaconda
blas 1.0 mkl anaconda
c-ares 1.15.0 h7b6447c_1 anaconda
ca-certificates 2018.12.5 0 anaconda
certifi 2018.11.29 py36_0 anaconda
cloudpickle 0.6.1 py36_0 anaconda
cycler 0.10.0 py36_0 anaconda
cytoolz 0.9.0.1 py36h14c3975_1 anaconda
dask-core 1.0.0 py36_0 anaconda
dbus 1.13.6 h746ee38_0 anaconda
decorator 4.3.0 py36_0 anaconda
expat 2.2.6 he6710b0_0 anaconda
fontconfig 2.13.0 h9420a91_0 anaconda
freetype 2.9.1 h8a8886c_1 anaconda
future 0.17.1 py36_0
gast 0.2.2 py36_0 anaconda
glib 2.56.2 hd408876_0 anaconda
grpcio 1.16.1 py36hf8bcb03_1 anaconda
gst-plugins-base 1.14.0 hbbd80ab_1 anaconda
gstreamer 1.14.0 hb453b48_1 anaconda
h5py 2.9.0 py36h7918eee_0 anaconda
hdf5 1.10.4 hb1b8bf9_0 anaconda
icu 58.2 h211956c_0 anaconda
imageio 2.4.1 py36_0 anaconda
intel-openmp 2019.1 144 anaconda
jpeg 9b habf39ab_1 anaconda
keras-applications 1.0.6 py36_0 anaconda
keras-preprocessing 1.0.5 py36_0 anaconda
kiwisolver 1.0.1 py36hf484d3e_0 anaconda
libedit 3.1.20181209 hc058e9b_0 anaconda
libffi 3.2.1 h4deb6c0_3 anaconda
libgcc-ng 8.2.0 hdf63c60_1 anaconda
libgfortran-ng 7.3.0 hdf63c60_0 anaconda
libpng 1.6.36 hbc83047_0 anaconda
libprotobuf 3.6.1 hd408876_0 anaconda
libstdcxx-ng 8.2.0 hdf63c60_1 anaconda
libtiff 4.0.10 h2733197_1001 anaconda
libuuid 1.0.3 h1bed415_2 anaconda
libxcb 1.13 h1bed415_1 anaconda
libxml2 2.9.9 he19cac6_0 anaconda
markdown 3.0.1 py36_0 anaconda
matplotlib 3.0.2 py36h5429711_0 anaconda
mkl 2019.1 144 anaconda
mkl_fft 1.0.10 py36ha843d7b_0 anaconda
mkl_random 1.0.2 py36hd81dba3_0 anaconda
ncurses 6.1 he6710b0_1 anaconda
networkx 2.2 py36_1 anaconda
numpy 1.15.4 py36h7e9f1db_0 anaconda
numpy-base 1.15.4 py36hde5b4d6_0 anaconda
odl 0.7.0 py36_0 odlgroup
olefile 0.46 py36_0 anaconda
openssl 1.1.1 h7b6447c_0 anaconda
packaging 18.0 py36_0
pcre 8.42 h439df22_0 anaconda
pillow 5.4.1 py36h34e0f95_0 anaconda
pip 18.1 py36_0 anaconda
protobuf 3.6.1 py36he6710b0_0 anaconda
pyparsing 2.3.1 py36_0 anaconda
pyqt 5.9.2 py36h22d08a2_1 anaconda
python 3.6.8 h0371630_0 anaconda
python-dateutil 2.7.5 py36_0 anaconda
pytz 2018.9 py36_0 anaconda
pywavelets 1.0.1 py36hdd07704_0 anaconda
qt 5.9.7 h5867ecd_1 anaconda
readline 7.0 h7b6447c_5 anaconda
scikit-image 0.14.1 py36he6710b0_0 anaconda
scipy 1.2.0 py36h7c811a0_0 anaconda
setuptools 40.6.3 py36_0 anaconda
sip 4.19.13 py36he6710b0_0 anaconda
six 1.12.0 py36_0 anaconda
sqlite 3.26.0 h7b6447c_0 anaconda
tensorboard 1.12.2 py36he6710b0_0 anaconda
tensorflow 1.12.0 mkl_py36h69b6ba0_0 anaconda
tensorflow-base 1.12.0 mkl_py36h3c3e929_0 anaconda
termcolor 1.1.0 py36_1 anaconda
tk 8.6.8 hbc83047_0 anaconda
toolz 0.9.0 py36_0 anaconda
tornado 5.1.1 py36h7b6447c_0 anaconda
werkzeug 0.14.1 py36_0 anaconda
wheel 0.32.3 py36_0 anaconda
xz 5.2.4 h14c3975_4 anaconda
zlib 1.2.11 h7b6447c_3 anaconda
I'm seeing some weird cycle here, e.g. the imports end up in "/home/banert/test.py". Due to the way python imports work this would override importing a odl library with the same name.
Could you try renaming test.py
to something else?
Yes, this is obviously the problem. Is it a Python problem or an ODL problem that you cannot choose this filename?
ODL is innocent here, but there should be protection against this (see https://python-future.org/_modules/future/standard_library.html). You can see that it tries to import e.g. test.py
, but there should be protection against it that apparently breaks somehow. I have no idea about how to fix it, but it's outside ODL so I'll close this.
The bug seems like this one PythonCharmers/python-future#268
Thank you for the explanation!
To elaborate for the future. Python has a test library (https://docs.python.org/3/library/test.html). This is apparently imported by the future library.
Due to the way lookup works in python, future will prefer files in your local folder before it looks in your pythonpath. Since it finds "test.py" in your local folder, it will prefer that over the official python library. This in turn causes a circular import, crashing your program.