Tensorflow 没有 Constant(但还有其他一切?)

Tensorflow doesn't have Constant (but has everything else?)

我最近在新的 Python 3.6.3 安装中使用 pip 安装了 Tensorflow。

以下代码:

import tensorflow as tf

msgconst = tf.Constant("henlo wrlod lol <4")
thesession = tf.Session()
print(thesession.run(msgconst))
thesession.close()

报错

Traceback (most recent call last):
  File "C:/Users/[my username]/PycharmProjects/TFlowTest/aergaetgaertgasrtg.py", line 3, in <module>
    msgconst = tf.Constant("henlo wrlod lol <4")
AttributeError: module 'tensorflow' has no attribute 'Constant'

问题不在于导入了另一个名为 tensorflow 的文件而不是真正的库;其他一切都存在。我可以做到这一点:

import tensorflow as tf
from tensorflow.python.framework import ops
ops.reset_default_graph()
print(tf.test.is_built_with_cuda())
print(tf.test.gpu_device_name())

给予

True
2017-12-06 21:03:22.807800: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-12-06 21:03:23.147288: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 980M major: 5 minor: 2 memoryClockRate(GHz): 1.1265
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.32GiB
2017-12-06 21:03:23.147553: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 980M, pci bus id: 0000:01:00.0, compute capability: 5.2)
/device:GPU:0

Process finished with exit code 0

这个问题在卸载并重新安装 Tensorflow 后仍然存在;这是 pip 在安装时打印的内容

C:\Program Files\Python36-64\Scripts>pip install tensorflow-gpu --no-cache-dir
Collecting tensorflow-gpu
  Downloading tensorflow_gpu-1.4.0-cp36-cp36m-win_amd64.whl (67.6MB)
    100% |████████████████████████████████| 67.6MB ...
Requirement already satisfied: numpy>=1.12.1 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: wheel>=0.26 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: six>=1.10.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: enum34>=1.1.6 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: tensorflow-tensorboard<0.5.0,>=0.4.0rc1 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: protobuf>=3.3.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-gpu)
Requirement already satisfied: html5lib==0.9999999 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
Requirement already satisfied: werkzeug>=0.11.10 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
Requirement already satisfied: markdown>=2.6.8 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
Requirement already satisfied: bleach==1.5.0 in c:\program files\python36-64\lib\site-packages (from tensorflow-tensorboard<0.5.0,>=0.4.0rc1->tensorflow-gpu)
Requirement already satisfied: setuptools in c:\program files\python36-64\lib\site-packages (from protobuf>=3.3.0->tensorflow-gpu)
Installing collected packages: tensorflow-gpu
Successfully installed tensorflow-gpu-1.4.0

有什么建议吗?

你会讨厌听到这个,但它

tf.constant(

没有

tf.Constant(

(注意第一个没有大写。)

我只是在我的环境中试玩了你的代码才注意到这一点,所以我可以说我确实在使用你的代码时遇到了问题,但是在使用一个小案例时它就起作用了 constant