简体   繁体   English

keras 在 PythonAnywhere 上运行多次时显示错误

[英]keras displays error when run more than once on PythonAnywhere

I am working on a file that imports the library "keras"我正在处理一个导入库“keras”的文件

I use python 3.8 using #!/usr/bin/python3.8我使用 #!/usr/bin/python3.8 使用 python 3.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:当我在控制台中导入 keras 或 tensorflow 时,它工作正常,但是,当我运行导入 keras 或 tensorflow 的文件时,它只运行一次,然后再次运行时,它会显示以下错误消息:

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注意:代码在本地使用 python3.9 运行时有效

note: i am not using python 3.9 on PythonAnywhere because tensorflow is not available for it注意:我没有在 PythonAnywhere 上使用 python 3.9,因为 tensorflow 不适用于它

i have also tried python3.7我也试过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.有些包不兼容在同一进程中多次导入,我们 (PythonAnywhere) 保留该进程,以便在第一次之后在编辑器中运行代码更快。 You can either run your code from the console or reset the console (with ctrl-D) when you want to run your code again.当您想再次运行代码时,您可以从控制台运行代码或重置控制台(使用 ctrl-D)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM