Error while trying to import TensorFlow

Hi, I am trying to import TensorFlow using Anaconda in Spyder. The python version I am using is 3.10.13. But I get the following error:

Traceback (most recent call last):

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\IPython\core\ in _pseudo_sync_runner

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\IPython\core\ in run_cell_async
    self.displayhook.exec_result = result

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\traitlets\ in __set__
    self.set(obj, value)

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\traitlets\ in set
    new_value = self._validate(obj, value)

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\traitlets\ in _validate
    value = self.validate(obj, value)

  File ~\anaconda3\envs\spyder-env\Lib\site-packages\traitlets\ in validate
    #     if isinstance(value, self.klass):  # type:ignore[arg-type]

TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

ERROR! Session/line number was not unique in database. History logging moved to new session 34

The corresponding part in the code in is:

    def validate(self, obj, value):
        assert self.klass is not None
        if isinstance(value, self.klass):  # type:ignore[arg-type]
            return value
            self.error(obj, value)

Is there someone that can help me out?

Hi @Joris, This error

occurs due the self.klass is not a type of a datatype in python. The arguments to be passed to the isinstance method should value, type of the data type in python like str,list,tuple, etc: If you pass any other value instead of dtype in python you will get this error.


instead of passing data types if you pass any other value

TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

So the error does not due to importing of tensorflow, it occurs from the python code. Thank You.