语法错误:在 “from keras.utils import to_categorical” 中。

huangapple go评论60阅读模式
英文:

SyntaxError in "from keras.utils import to_categorical"

问题

语法错误:在 “from keras.utils import to_categorical” 中。
在运行涉及关系抽取的代码时遇到问题。我的环境是Python2.7.17,VScode中的Python扩展版本是2022.2.1924087327。我不知道为什么会出现SyntaxError。当我搜索关于from keras.utils import to_categorical的问题时,几乎所有的答案都是将其更改为from tensorflow.keras.utils import to_categorical。但这与我的问题不同。有人能帮我吗?

当我想在Python 2.7.17而不是3.7中运行代码时,我应该怎么做?

英文:

语法错误:在 “from keras.utils import to_categorical” 中。
I have a problem when I try to run the code which is about a Relation Extraction. My environment is Python2.7.17. The version of python extention in VScode is 2022.2.1924087327.
I dont know why it occurs SyntaxError. When I search the problem about from keras.utils import to_categorical, almost all the answer is to change it into from tensorflow.keras.utils import to_categorical. But it is different from My problem.
Can anybody help me?

When I want to run the code in Python 2.7.17 not 3.7, what should I do?

答案1

得分: 1

无法在Python==2或Python<3.6上使用keras,因为keras使用f-strings:

from keras.utils import to_categorical
  File "/home/user/.pyenv/versions/2.7.18/lib/python2.7/site-packages/keras/distribute/sidecar_evaluator.py", line 195
    f"{_CHECKPOINT_TIMEOUT_SEC} seconds. "
    ^
SyntaxError: invalid syntax
英文:

You can't use keras with neither Python==2 nor Python<3.6 because keras use f-strings:

In [1]: from keras.utils import to_categorical
  File &quot;/home/user/.pyenv/versions/2.7.18/lib/python2.7/site-packages/keras/distribute/sidecar_evaluator.py&quot;, line 195
    f&quot;{_CHECKPOINT_TIMEOUT_SEC} seconds. &quot;
    ^
SyntaxError: invalid syntax

huangapple
  • 本文由 发表于 2023年4月17日 16:59:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定