gpt4 book ai didi

使用 'as'导入时Python模块没有属性错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:51:39 25 4
gpt4 key购买 nike

我想从 Tensorflow 库导入 Keras。所以我做了以下事情:

import tensorflow.python.keras as keras

但是此导入会引发错误:

AttributeError: module 'tensorflow' has no attribute 'python'

看来以下导入工作正常:

import tensorflow.python.keras
from tensorflow.python import keras

对我来说,importtensorflow.python.keras as kerasfromtensorflow.python import keras是相同的,但看起来并不正确。这两个导入有什么区别?

最佳答案

你应该尝试这样的事情:

import tensorflow as tf
import tensorflow

from tensorflow import keras
from keras.layers import Dense
# ...

第一行帮助您使用带有 tf 短名称 (asname) 的 tensorflow 模块。

对于asname,你可以检查这个thread .

关于使用 'as'导入时Python模块没有属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56272027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com