0

This is my code:-

  import pandas as pd
  import numpy as np

  import matplotlib.pyplot as plt


   from matplotlib.pylab import rcParams
   rcParams['figure.figsize']=20,10
   from keras import Sequential
   from keras import LSTM,Dropout,Dense


    from sklearn.preprocessing import MinMaxScaler
    df=pd.read_csv("/Users/apple/Desktop/NSE-Tata-Global-Beverages-Limited.csv")
    df.head()
    df["Date"]=pd.to_datetime(df.Date,format="%Y-%m-%d")
    df.index=df['Date']

    plt.figure(figsize=(16,8))
    plt.plot(df["Close"],label='Close Price history')

It shows error as follows:-

   Users/apple/PycharmProjects/pythonProject4/venv/bin/python /Users/apple/PycharmProjects/pythonProject4/main.py 
   Traceback (most recent call last):
   File "/Users/apple/PycharmProjects/pythonProject4/main.py", line 9, in <module>
   from keras import Sequential
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/keras/__init__.py", line 21, in <module>
   from keras import models
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/keras/models/__init__.py", line 18, in <module>
   from keras.engine.functional import Functional
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/keras/engine/functional.py", line 24, in <module>
   import tensorflow.compat.v2 as tf
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/__init__.py", line 24, in <module>
   from tensorflow.python import *
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/__init__.py", line 75, in <module>
   from tensorflow.core.framework.graph_pb2 import *
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
   from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
   File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/core/framework/node_def_pb2.py", line 16, in <module>
   from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
    from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
    from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-  packages/tensorflow/core/framework/resource_handle_pb2.py", line 36, in <module>
    _descriptor.FieldDescriptor(
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site- packages/google/protobuf/descriptor.py", line 560, in __new__
   _message.Message._CheckCalledFromGeneratedFile()
    TypeError: Descriptors cannot not be created directly.
    If this call came from a _pb2.py file, your generated code is out of date and must          be regenerated with protoc >= 3.19.0.
     If you cannot immediately regenerate your protos, some other possible workarounds   are:
    1. Downgrade the protobuf package to 3.20.x or lower.
    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-  Python parsing and will be much slower).

     More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

     Process finished with exit code 1

I have installed both "keras" and "tensorflow both through the interpreter. Using pycharm 3. What is to be done? I have tried installling keras and tensorflow throguh the terminal as well. I have tried everything. Thank you for going through my question.

I did what Yevhen Kuzmovych told and now the error is:-

   /Users/apple/PycharmProjects/pythonProject4/venv/bin/python  /Users/apple/PycharmProjects/pythonProject4/main.py 
   /Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/dtypes.py:471:           FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as   (type, (1,)) / '(1,)type'.
     _np_qint8 = np.dtype([("qint8", np.int8, 1)])
      /Users/apple/PycharmProjects/pythonProject4/venv/lib /python3.11/site-packages/tensorflow/python/framework/dtypes.py:472:   FutureWarning: Passing (type, 1) or '1type' as a synonym of type is     deprecated; in a future version of numpy, it will be understood as   (type, (1,)) / '(1,)type'.
       _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
        /Users/apple/PycharmProjects/pythonProject4/venv/lib         /python3.11/site-packages/tensorflow/python/framework/dtypes.py:473:           FutureWarning: Passing (type, 1) or '1type' as a synonym of type is  deprecated; in a future version of numpy, it will be understood as   (type, (1,)) / '(1,)type'.
          _np_qint16 = np.dtype([("qint16", np.int16, 1)])
         /Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/dtypes.py:474: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
            _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
            /Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/dtypes.py:475: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
    _    np_qint32 = np.dtype([("qint32", np.int32, 1)])
         /Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/dtypes.py:490: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.  (This may have returned Python scalars in past versions.
    (np.object, string),
     Traceback (most recent call last):
     File "/Users/apple/PycharmProjects/pythonProject4/main.py", line 9, in <module>
       from keras import Sequential
     File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/keras/__init__.py", line 21, in <module>
      from keras import models
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib /python3.11/site-packages/keras/models/__init__.py", line 18, in  <module>
     from keras.engine.functional import Functional
    File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/keras/engine/functional.py", line 24, in <module>
      import tensorflow.compat.v2 as tf
        File "/Users/apple/PycharmProjects/pythonProject4/venv/lib /python3.11/site-packages/tensorflow/__init__.py", line 24, in <module>
      from tensorflow.python import *
         File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/__init__.py", line 84, in <module>
      from tensorflow.python.framework.framework_lib import *
          File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/framework_lib.py", line 73, in <module>
      from tensorflow.python.framework.ops import Graph
      File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/ops.py", line 39, in <module>
      from tensorflow.python.framework import dtypes
      File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/tensorflow/python/framework/dtypes.py", line 490, in <module>
     (np.object, string),
       ^^^^^^^^^
     File "/Users/apple/PycharmProjects/pythonProject4/venv/lib/python3.11/site-packages/numpy/__init__.py", line 284, in __getattr__
     raise AttributeError("module {!r} has no attribute "
   AttributeError: module 'numpy' has no attribute 'object'. Did   you  mean: 'object_'?

    Process finished with exit code 1
askit
  • 205
  • 4
  • 21
  • possible duplicate https://stackoverflow.com/questions/72441758/typeerror-descriptors-cannot-not-be-created-directly – imM4TT Jan 25 '23 at 08:37

2 Answers2

1

As the error message states, you can try downgrading protobuf:

pip install --force-reinstall -v "protobuf~=3.20.0"
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
1

You can try the steps provided in the github discussion: https://github.com/ipython/ipyparallel/issues/349#issuecomment-449402168

Most probably the error is due to the circular dependencies which is used by tensorflow and keras.

And if the python version is not a very strict barrier, I would suggest to use the previous release like 3.10

Harshit Ruwali
  • 1,040
  • 2
  • 10
  • 22
  • Utimately I downgraded python to 3.10, now shows error as follows"/Users/apple/PycharmProjects/pythonProject4/venv/bin/python /Users/apple/PycharmProjects/pythonProject4/main.py 2023-01-25 18:22:46.843114: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags." – askit Jan 25 '23 at 12:54
  • This does not seem like an error and its not one. Its just log message from tensorflow. More details down here: https://stackoverflow.com/questions/65298241/what-does-this-tensorflow-message-mean-any-side-effect-was-the-installation-su https://stackoverflow.com/questions/35911252/disable-tensorflow-debugging-information/42121886#42121886 – Harshit Ruwali Jan 25 '23 at 15:30
  • Then why is it showing exit code 1 ? – askit Jan 27 '23 at 04:30
  • Maybe something wrong with the code or other library. Try to just import tensorflow and check once. Because I dont see any problem. – Harshit Ruwali Jan 27 '23 at 07:07