I am working on a file that imports the library "keras"
I use python 3.8 using #!/usr/bin/python3.8
when I import keras or tensorflow in a console, it works fine, However, when I run a file that imports keras or tensorflow, it only runs once then when it's run again, it diplays this error message:
TypeError: A Message class can only inherit from Message
and the problem persists unless i close the console and then reopen it
is there any solution for this?
note: the code works when run locally with python3.9
note: i am not using python 3.9 on PythonAnywhere because tensorflow is not available for it
i have also tried python3.7
full traceback:
Traceback (most recent call last):
File "/home/leto/mysite/what.py", line 2, in <module>
import keras
File "/usr/local/lib/python3.8/dist-packages/keras/__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
File "/usr/local/lib/python3.8/dist-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/__init__.py", line 41, in <module>
from tensorflow.python.eager import context
File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/eager/context.py", line 32, in <module>
from tensorflow.core.framework import function_pb2
File "/usr/local/lib/python3.8/dist-packages/tensorflow/core/framework/function_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 "/usr/local/lib/python3.8/dist-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 "/usr/local/lib/python3.8/dist-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 "/usr/local/lib/python3.8/dist-packages/tensorflow/core/framework/resource_handle_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/usr/local/lib/python3.8/dist-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 110, in <module>
'Dim' : _reflection.GeneratedProtocolMessageType('Dim', (_message.Message,), {
TypeError: A Message class can only inherit from Message
>>>
Some packages are not compatible with being imported multiple times in the same process and we (PythonAnywhere) keep the process around so that running your code in the editor is faster after the first time. You can either run your code from the console or reset the console (with ctrl-D) when you want to run your code again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.