英文:
SyntaxError in "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中运行代码时,我应该怎么做?
英文:
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 "/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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论