'hello everyone, Iam new to programming, I am using jupyter notebook using anaconda, here i found some problem with the importing of libraries

# lstm model
import tensorflow as tf
from numpy import mean
from numpy import std
from numpy import dstack
from pandas import read_csv
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import LSTM
from tensorflow.keras.utils import to_categorical
from matplotlib import pyplot

When i run this cell iam getting the below error, I am using jupyter notebook using anaconda, using anaconda every packages will be installed related to python but in this it is showing regarding tensorflow problem while the importing libraries, I am using latest version of python 3.9,would anyone help to resolve the issue

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10616/748904884.py in <module>
       1 # lstm model
 ----> 2 import tensorflow as tf
       3 from numpy import mean
       4 from numpy import std
       5 from numpy import dstack

~\AppData\Roaming\Python\Python39\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 

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\__init__.py in <module>
     44 
     45 # Bring in subpackages.
---> 46 from tensorflow.python import data
     47 from tensorflow.python import distribute
     48 # from tensorflow.python import keras

~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\data\__init__.py in <module>
     23 
     24 # pylint: disable=unused-import
---> 25 from tensorflow.python.data import experimental
     26 from tensorflow.python.data.ops.dataset_ops import AUTOTUNE
     27 from tensorflow.python.data.ops.dataset_ops import Dataset

~\AppData\Roaming\Python\Python39\sitepackages\tensorflow\python\data\experimental\__init__.py 
   in <module>
     96 
     97 # pylint: disable=unused-import
---> 98 from tensorflow.python.data.experimental import service
     99 from tensorflow.python.data.experimental.ops.batching import dense_to_ragged_batch
    100 from tensorflow.python.data.experimental.ops.batching import dense_to_sparse_batch

  ~\AppData\Roaming\Python\Python39\site- 
  packages\tensorflow\python\data\experimental\service\__init__.py in <module>
    372 from __future__ import print_function
    373 
--> 374 from tensorflow.python.data.experimental.ops.data_service_ops import distribute
    375 from tensorflow.python.data.experimental.ops.data_service_ops import from_dataset_id
    376 from tensorflow.python.data.experimental.ops.data_service_ops import register_dataset

~\anaconda3\envs\mygpu\lib\site- 
 packages\tensorflow\python\data\experimental\ops\data_service_ops.py in <module>
     23 
     24 from tensorflow.python import tf2
---> 25 from tensorflow.python.data.experimental.ops import compression_ops
     26 from tensorflow.python.data.experimental.ops.distribute_options import AutoShardPolicy
     27 from tensorflow.python.data.experimental.ops.distribute_options import 
        ExternalStatePolicy

~\anaconda3\envs\mygpu\lib\site- 
    packages\tensorflow\python\data\experimental\ops\compression_ops.py in <module>
     18 from __future__ import print_function
     19 
---> 20 from tensorflow.python.data.util import structure
     21 from tensorflow.python.ops import gen_experimental_dataset_ops as ged_ops
     22 

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\structure.py in <module>
     24 import wrapt
     25 
---> 26 from tensorflow.python.data.util import nest
     27 from tensorflow.python.framework import composite_tensor
     28 from tensorflow.python.framework import ops

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\data\util\nest.py in <module>
     38 import six as _six
     39 
---> 40 from tensorflow.python.framework import sparse_tensor as _sparse_tensor
     41 from tensorflow.python.util import _pywrap_utils
     42 from tensorflow.python.util import nest

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\sparse_tensor.py in 
 <module>
     26 from tensorflow.python import tf2
     27 from tensorflow.python.framework import composite_tensor
---> 28 from tensorflow.python.framework import constant_op
     29 from tensorflow.python.framework import dtypes
     30 from tensorflow.python.framework import ops

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\constant_op.py in 
  <module>
     27 from tensorflow.core.framework import types_pb2
     28 from tensorflow.python.eager import context
---> 29 from tensorflow.python.eager import execute
     30 from tensorflow.python.framework import dtypes
     31 from tensorflow.python.framework import op_callbacks

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\eager\execute.py in <module>
     25 from tensorflow.python import pywrap_tfe
     26 from tensorflow.python.eager import core
---> 27 from tensorflow.python.framework import dtypes
     28 from tensorflow.python.framework import ops
     29 from tensorflow.python.framework import tensor_shape

~\anaconda3\envs\mygpu\lib\site-packages\tensorflow\python\framework\dtypes.py in <module>
     30 from tensorflow.python.util.tf_export import tf_export
     31 
---> 32 _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()
     33 
     34 

TypeError: Unable to convert function return value to a Python type! The signature was
    () -> handle


Solution 1:[1]

First try to install each package one by one and you will be able to use it at once.

Solution 2:[2]

I was having this issue on m1 macbook, turns out my tensorflow dependency was not in sync with my tensorflow-macos package. This would be a good place to check, In this page the version they give is 2.6.0 but the newest version for tf-macos when running this command python -m pip install tensorflow-macos gives 2.8.0 thus the error. If you just updated your tensorflow version this could very well be there case, go through you tensorflow dependencies and see if there's a mix up.

If that doesn't solve it, then yeah install tokenizer first then transformer, see if that solves the issue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak
Solution 2 Leo Liu