ImportError: cannot import name 'ClusterDef' - python

About a week ago I was able to import tensor flow but now I seem to have a problem running the same code. When I run either of these I am not able to get it to work at this point (what surprises me the most is at least part of it worked last week, now it does not seem to work), I get ImportError: cannot import name 'ClusterDef' which I am not finding anything online on:
import tensorflow
import keras
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a649b509054f> in <module>()
----> 1 import tensorflow
/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py in <module>()
39 import sys as _sys
40
---> 41 from tensorflow.python.tools import module_util as _module_util
42 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
43
/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py in <module>()
75
76 # Bring in subpackages.
---> 77 from tensorflow.python.estimator import estimator_lib as estimator
78 from tensorflow.python.layers import layers
79 from tensorflow.python.ops import image_ops as image
/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator_lib.py in <module>()
20
21 # pylint: disable=unused-import,line-too-long
---> 22 from tensorflow.python.estimator.estimator import Estimator
23 from tensorflow.python.estimator.export import export_lib as export
24 from tensorflow.python.estimator.inputs import inputs
/anaconda3/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py in <module>()
48 from tensorflow.python.training import monitored_session
49 from tensorflow.python.training import saver
---> 50 from tensorflow.python.training import training
51 from tensorflow.python.util import compat
52
/anaconda3/lib/python3.6/site-packages/tensorflow/python/training/training.py in <module>()
180
181 # Distributed computing support.
--> 182 from tensorflow.core.protobuf.tensorflow_server_pb2 import ClusterDef
183 from tensorflow.core.protobuf.tensorflow_server_pb2 import JobDef
184 from tensorflow.core.protobuf.tensorflow_server_pb2 import ServerDef
ImportError: cannot import name 'ClusterDef'

There is usually two reasons for ImportError
it's circular import attempt
the target object does not exist
in your case i would check if this file really contains ClusterDef class
/anaconda3/lib/python3.6/site-packages/tensorflow/core/protobuf/tensorflow_server_pb2.py
this is dynamically generated protobuf files (by grpc), which could somehow got deleted
in case this file does not contain needed class the best option is probably reinstall tensorflow/anaconda

Related

Cannot import tensorflow after a week of no use, no changes was made

What I've did:
uninstall and pip install tensorflow-macos
uninstall pip install tensorflow-metal
import tensorflow as tf
The expected result is no error.
However, I got an error after importing tensorflow.
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import tensorflow as tf
3 # from keras import datasets, layers, models
4 # import matplotlib.pyplot as plt
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/__init__.py:37
34 import sys as _sys
35 import typing as _typing
---> 37 from tensorflow.python.tools import module_util as _module_util
38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/__init__.py:45
43 from tensorflow.python import distribute
44 # from tensorflow.python import keras
---> 45 from tensorflow.python.feature_column import feature_column_lib as feature_column
46 # from tensorflow.python.layers import layers
47 from tensorflow.python.module import module
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tensorflow/python/feature_column/feature_column_lib.py:18
15 """FeatureColumns: tools for ingesting and representing features."""
17 # pylint: disable=unused-import,line-too-long,wildcard-import,g-bad-import-order
---> 18 from tensorflow.python.feature_column.feature_column import *
...
(...)
3248 :returns: The PKCS12 object
3249 """
TypeError: deprecated() got an unexpected keyword argument 'name'

ModelicaRes import fails in python

I want to use ModelicaRes to open my Dymola results in python but the import fails.
from modelicares.simres import SimRes
Gives the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In [2], line 1
----> 1 from modelicares.simres import SimRes
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\__init__.py:54
40 __version__ = '0.12.2'
43 # Standard pylint settings for this project:
44 # pylint: disable=I0011, C0302, C0325, R0903, R0904, R0912, R0913, R0914, R0915,
45 # pylint: disable=I0011, W0141, W0142
(...)
52 # These will be available directly from modelicares; others must be loaded from
53 # their submodules.
---> 54 from modelicares.simres import SimRes, SimResList
55 from modelicares.linres import LinRes, LinResList
56 from modelicares.util import (add_arrows, add_hlines, add_vlines, ArrowLine,
57 closeall, multiglob, figure, load_csv, save,
58 saveall, setup_subplots)
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\simres.py:50
48 from itertools import cycle
49 from matplotlib import rcParams
---> 50 from matplotlib.cbook import iterable
51 from matplotlib.pyplot import figlegend
52 from pandas import DataFrame
ImportError: cannot import name 'iterable' from 'matplotlib.cbook' (C:\ProgramData\Miniforge3\envs\main\lib\site-packages\matplotlib\cbook\__init__.py)
I tried DyMat and Buildingspy but I would prefer to use ModelicaRes. Because Buildingspy makes use of DyMat which is quiet old and seems unmaintained.
I also had this issue.
I fixed this in my fork of modelicares here: https://github.com/sede-fa/ModelicaRes
I basically replaced any reference to matplotlib.cbook to numpy to get the iterable function as shown here: https://github.com/kdavies4/ModelicaRes/issues/42
You can install this via pip by doing: pip install git+https://github.com/sede-fa/ModelicaRes.git

Scikitlearn in Jupyter notebook using Anaconda

This is not a duplicate because the linked question does not address how to either locate the required dlls or fix the installation.
I get the following when I try import sklearn v.0.20. I'm using anaconda and both numpy and scipy are up to date.
ImportError Traceback (most recent call last)
<ipython-input-1-8fd979e02004> in <module>()
----> 1 import sklearn
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\__init__.py in <module>()
62 else:
63 from . import __check_build
---> 64 from .base import clone
65 from .utils._show_versions import show_versions
66
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\base.py in <module>()
11 from scipy import sparse
12 from .externals import six
---> 13 from .utils.fixes import signature
14 from . import __version__
15
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>()
11
12 from .murmurhash import murmurhash3_32
---> 13 from .validation import (as_float_array,
14 assert_all_finite,
15 check_random_state, column_or_1d, check_array,
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>()
20
21 from ..externals import six
---> 22 from ..utils.fixes import signature
23 from .. import get_config as _get_config
24 from ..exceptions import NonBLASDotWarning
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>()
81 return stats.boxcox(x, lmbda)
82 else:
---> 83 from scipy.special import boxcox # noqa
84
85
C:\Users\James2SxyBoogaloo\Anaconda3\lib\site-packages\scipy\special\__init__.py in <module>()
638 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
639
--> 640 from ._ufuncs import *
641
642 from .basic import *
ImportError: DLL load failed: The specified module could not be found.
EDIT:
I found this thread : https://github.com/numpy/numpy/issues/10965
That mentions a problem related to this.
So it seems the guy there solved his problem by removing both numpy and scipy and reinstalling them. There is a chance your version of scipy for some reason is linked against a MLK version of numpy and that's the reason things don't work.
END OF EDIT
I checked around for your problem and it seems that this is related to the version of numpy you have.
To fix the problem you should install numpy-MLK which is a version on numpy linked against Intel's Math Kernel Library.
You can find it here:
https://pypi.org/project/numpy-mkl/
Just remember to first remove the already existing numpy package.
You can find more info here:
ImportError when importing certain modules from SciPY
and here:
Difference between Numpy and Numpy-MKL?

h5py errors after installation

I'm trying to install h5py on Mac OSX and use it's group and dataset features, but I'm having an issue. On its installation webpage it says the easiest way for beginners to use it on Mac is to install Anaconda, so that's what I did since I would still consider myself an inexperienced programmer. Anyway, after installing Anaconda and typing the following script into iPython Notebook, I get an "image not found error."
import h5py
import numpy as np
f = h5py.File("mytestfile.hdf5" , "w")
Here is the full error (its pretty long):
ImportError Traceback (most recent call last)
<ipython-input-1-65d72c32bd56> in <module>()
----> 1 import h5py
2 import numpy as np
3
4 f = h5py.File("mytestfile.hdf5", "w")
/Users/wlentzii/anaconda/lib/python2.7/site-packages/h5py/__init__.py in <module>()
21 _errors.silence_errors()
22
---> 23 from . import _conv
24 _conv.register_converters()
25
h5py/h5t.pxd in init h5py._conv (-------src-dir--------/h5py/_conv.c:6961)()
h5py/numpy.pxd in init h5py.h5t (-------src-dir--------/h5py/h5t.c:19623)()
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/__init__.pyc in <module>()
166 return loader(*packages, **options)
167
--> 168 from . import add_newdocs
169 __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
170
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/numpy/lib/__init__.py in <module>()
16
17 from . import scimath as emath
---> 18 from .polynomial import *
19 #import convertcode
20 from .utils import *
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/polynomial.py in <module>()
17 from numpy.lib.function_base import trim_zeros, sort_complex
18 from numpy.lib.type_check import iscomplex, real, imag
---> 19 from numpy.linalg import eigvals, lstsq, inv
20
21 class RankWarning(UserWarning):
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/__init__.py in <module>()
48 from .info import __doc__
49
---> 50 from .linalg import *
51
52 from numpy.testing import Tester
/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/linalg.py in <module>()
27 )
28 from numpy.lib import triu, asfarray
---> 29 from numpy.linalg import lapack_lite, _umath_linalg
30 from numpy.matrixlib.defmatrix import matrix_power
31 from numpy.compat import asbytes
ImportError: dlopen(/Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib /python2.7/site-packages/numpy/linalg/lapack_lite.so, 2): Library not loaded: #rpath/lib/libmkl_intel_lp64.dylib
Referenced from: /Users/wlentzii/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/lapack_lite.so
Reason: image not found
Your traceback shows that you are using Canopy's Python, not Anaconda's. Either (1) make sure Anaconda appears in your system path before Canopy or (2) use Canopy's package manager to install h5py. Since you have Canopy installed already, and that's what appears first in your path already, that might be the easiest choice for you. You can either use the graphical Package Manager (reachable from the Welcome screen) or install h5py from the command-line
enpkg h5py

Ipython notebook. %pylab load error in Windows 7

I run Windows 7, Enthought Python Distribution 7.3-2 Academic.
I open a command prompt, change to my code directory and type
U:\rsch>ipython notebook
In a new notebook, I type %pylab and receive the following error:
In [1]: %pylab
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
U:\rsch\<ipython-input-1-5c1faa999e5b> in <module>()
----> 1 get_ipython().magic(u'pylab')
D:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s, next_input)
1983 self._magic_locals = sys._getframe(1).f_locals
1984 with self.builtin_trap:
-> 1985 result = fn(magic_args)
1986 # Ensure we're not keeping object references around:
1987 self._magic_locals = {}
D:\Python27\lib\site-packages\IPython\core\magic.pyc in magic_pylab(self, s)
3471 import_all_status = True
3472
-> 3473 self.shell.enable_pylab(s, import_all=import_all_status)
3474
3475 def magic_tb(self, s):
D:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in enable_pylab(self, gui, import_all)
2592 ns = {}
2593 try:
-> 2594 gui = pylab_activate(ns, gui, import_all, self)
2595 except KeyError:
2596 error("Backend %r not supported" % gui)
D:\Python27\lib\site-packages\IPython\core\pylabtools.pyc in pylab_activate(user_ns, gui, import_all, shell)
327 itself, and will be needed next to configure IPython's gui integration.
328 """
--> 329 gui, backend = find_gui_and_backend(gui)
330 activate_matplotlib(backend)
331 import_pylab(user_ns, import_all)
D:\Python27\lib\site-packages\IPython\core\pylabtools.pyc in find_gui_and_backend(gui)
194 """
195
--> 196 import matplotlib
197
198 if gui and gui != 'auto':
D:\Python27\lib\site-packages\matplotlib\__init__.py in <module>()
131 import sys, os, tempfile
132
--> 133 from matplotlib.rcsetup import (defaultParams,
134 validate_backend,
135 validate_toolbar,
D:\Python27\lib\site-packages\matplotlib\rcsetup.py in <module>()
17 import warnings
18 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
---> 19 from matplotlib.colors import is_color_like
20
21 #interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'fltkagg', 'qtagg', 'qt4agg',
D:\Python27\lib\site-packages\matplotlib\colors.py in <module>()
50 """
51 import re
---> 52 import numpy as np
53 from numpy import ma
54 import matplotlib.cbook as cbook
D:\Python27\lib\site-packages\numpy\__init__.pyc in <module>()
141 return loader(*packages, **options)
142
--> 143 import add_newdocs
144 __all__ = ['add_newdocs']
145
D:\Python27\lib\site-packages\numpy\add_newdocs.py in <module>()
7 # core/fromnumeric.py, core/defmatrix.py up-to-date.
8
----> 9 from numpy.lib import add_newdoc
10
11 ###############################################################################
D:\Python27\lib\site-packages\numpy\lib\__init__.py in <module>()
11
12 import scimath as emath
---> 13 from polynomial import *
14 #import convertcode
15 from utils import *
D:\Python27\lib\site-packages\numpy\lib\polynomial.py in <module>()
15 from numpy.lib.function_base import trim_zeros, sort_complex
16 from numpy.lib.type_check import iscomplex, real, imag
---> 17 from numpy.linalg import eigvals, lstsq
18
19 class RankWarning(UserWarning):
D:\Python27\lib\site-packages\numpy\linalg\__init__.py in <module>()
46 from info import __doc__
47
---> 48 from linalg import *
49
50 from numpy.testing import Tester
D:\Python27\lib\site-packages\numpy\linalg\linalg.py in <module>()
21 isfinite, size, finfo, absolute, log, exp
22 from numpy.lib import triu
---> 23 from numpy.linalg import lapack_lite
24 from numpy.matrixlib.defmatrix import matrix_power
25 from numpy.compat import asbytes
ImportError: DLL load failed: The specified path is invalid.
Not sure what to do. Thanks.
I experienced the same problem and here is what worked for me:
I made sure I call the IPython without "pylab"
I then made sure all sessions/instances (excuse me but I'm new to this :) are closed. You can do this by ctrl-C in all Terminals and in the Notebook dashboard press "shutdown" if possible.
There are probably more elegant ways to do this but this is what worked for me.
Developers, take note that many newbies might get very frustrated when the first notebook they try to run gives them an error.
Adam
It's likely that you're missing the Scripts directory in your system path. To check, run
echo %PATH%
from the command prompt and look for D:\Python27\Scripts. If it's missing, you can add it manually from the Control Panel, or using a utility like Rapid Environment Editor.
EPD shipped with ipython 0.12. Ipython has developed a lot since then. You should update to ipython 0.13.1 by entering "enpkg ipython", as described in more detail here:
https://support.enthought.com/entries/22415022-Using-enpkg-to-update-EPD-packages
Unfortunately these error messages arent really useful. From the message you only know that 'some dll' fails to import during the import of "lapack_lite" (part of Numpy).
You can use Dependency Walker to see which specific DLL is causing the problem, opening "D:\Python27\Lib\site-packages\numpy\linalg\lapack_lite.pyd" might reveal some more information.

Categories

Resources