【发布时间】:2020-02-27 09:40:21
【问题描述】:
我是 TensorFlow 的新手,今天我尝试安装它并让它在 PyCharm 中运行。我使用了我在网上找到的普通“pip3 install TensorFlow”。当我在 PyCharm 中导入 TensorFlow 时,我没有收到任何导入错误,但我的示例代码无法正常运行。 有谁知道我该如何解决这个问题,或者有任何非常好的 TensorFlow 完整教程?
顺便说一句,我在 macOS Catalina 上使用 MacBook Pro,并运行 Python 3.7.4。我对使用 PyCharm 也很陌生。
代码
# Import `tensorflow`
import tensorflow as tf
# Initialize two constants
x1 = tf.constant([1, 2, 3, 4])
x2 = tf.constant([5, 6, 7, 8])
hello = tf.constant("Hello World!")
# Multiply
result = tf.multiply(x1, x2)
# Intialize the Session
sess = tf.Session()
# Print the result
print(sess.run(hello))
print(sess.run(result))
# Close the session
sess.close()
输出
/Users/anttesoriero/PycharmProjects/TensorTest/venv/bin/python /Users/anttesoriero/PycharmProjects/TensorTest/venv/main.py
2019-10-31 22:06:28.027494: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-10-31 22:06:28.052950: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f9ca1b4fa30 executing computations on platform Host. Devices:
2019-10-31 22:06:28.052970: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "/Users/anttesoriero/PycharmProjects/TensorTest/venv/main.py", line 13, in <module>
sess = tf.Session()
AttributeError: module 'tensorflow' has no attribute 'Session'
Process finished with exit code 1
我还将在下面附上我所有代码和输出的屏幕截图。 TensorFlow code and error output
【问题讨论】:
-
请添加您正在使用的TensorFlow版本。
标签: python tensorflow pycharm