无法使用tensorflow在python中定义变量?

无法使用tensorflow在python中定义变量?,python,tensorflow,python-idle,tensorflow-gpu,Python,Tensorflow,Python Idle,Tensorflow Gpu,我正在尝试运行简单的tensorflow hello world程序,但它不在cmd上运行,但相同的代码在Python IDLE上运行。我如何在cmd上运行它?以下是我键入的内容: Microsoft Windows[版本10.0.15063] (c) 2017年微软公司。版权所有 C:\Users\Manish>python Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.190

我正在尝试运行简单的tensorflow hello world程序,但它不在cmd上运行,但相同的代码在Python IDLE上运行。我如何在cmd上运行它?以下是我键入的内容:

Microsoft Windows[版本10.0.15063] (c) 2017年微软公司。版权所有

C:\Users\Manish>python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Manish\tensorflow.py", line 2, in <module>
    hello = tf.constant('Hello, TensorFlow!')
AttributeError: module 'tensorflow' has no attribute 'constant'
>>> hello = tf.constant('Hello Man')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> sess = tf.Session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> print(sess.run(hello))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sess' is not defined
>>>
C:\Users\Manish>python
win32上的Python 3.6.1 | Anaconda 4.4.0(64位)|(默认,2017年5月11日,13:25:24)[MSC v.1900 64位(AMD64)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入tensorflow作为tf
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Users\Manish\tensorflow.py”,第2行,在
hello=tf.constant('hello,TensorFlow!')
AttributeError:模块“tensorflow”没有属性“constant”
>>>hello=tf.constant('hello Man')
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“tf”
>>>sess=tf.Session()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“tf”
>>>打印(sess.run(hello))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“sess”
>>>
更新: 删除文件后,我面临新的错误

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Manish>activte tensorflow-gpu
'activte' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Manish>activate tensorflow-gpu

(tensorflow-gpu) C:\Users\Manish>python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 560, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 922, in create_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
Microsoft Windows[版本10.0.15063]
(c) 2017年微软公司。版权所有。
C:\Users\Manish>activte tensorflow gpu
“activte”未被识别为内部或外部命令,
可操作的程序或批处理文件。
C:\Users\Manish>激活tensorflow gpu
(tensorflow gpu)C:\Users\Manish>python
win32上的Python 3.6.1 | Continuum Analytics,Inc.|(默认,2017年5月11日,13:25:24)[MSC v.1900 64位(AMD64)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入tensorflow作为tf
回溯(最近一次呼叫最后一次):
swig\u import\u helper中的文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”第18行
返回导入lib.import\u模块(mname)
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\importlib\\uuuu init\uuuu.py”,第126行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第978行,在_gcd_import中
文件“”,第961行,在“查找”和“加载”中
文件“”,第950行,在“查找”和“加载”中解锁
文件“”,第648行,在“加载”中
文件“”,第560行,在_规范的模块_中
文件“”,第922行,在“创建”模块中
文件“”,第205行,在调用中删除了帧
ImportError:DLL加载失败:找不到指定的模块。
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow.py”,第41行,在
从tensorflow.python.pywrap\u tensorflow\u内部导入*
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”,第21行,in
_pywrap\u tensorflow\u internal=swig\u import\u helper()
swig\u import\u helper中的文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”第20行
返回importlib.import\u模块(“pywrap\u tensorflow\u internal”)
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\importlib\\uuuu init\uuuu.py”,第126行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
ModuleNotFoundError:没有名为“\u pywrap\u tensorflow\u internal”的模块
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\\uuuuu init\uuuu.py”,第24行,在
从tensorflow.python导入*
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\\uuuu init\uuuu.py”,第49行,在
从tensorflow.python导入pywrap\u tensorflow
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow.py”,第52行,在
提高效率(msg)
ImportError:回溯(最近一次呼叫上次):
swig\u import\u helper中的文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”第18行
返回导入lib.import\u模块(mname)
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\importlib\\uuuu init\uuuu.py”,第126行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第978行,在_gcd_import中
文件“”,第961行,在“查找”和“加载”中
文件“”,第950行,在“查找”和“加载”中解锁
文件“”,第648行,在“加载”中
文件“”,第560行,在_规范的模块_中
文件“”,第922行,在“创建”模块中
文件“”,第205行,在调用中删除了帧
ImportError:DLL加载失败:找不到指定的模块。
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow.py”,第41行,在
从tensorflow.python.pywrap\u tensorflow\u内部导入*
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”,第21行,in
_pywrap\u tensorflow\u internal=swig\u import\u helper()
swig\u import\u helper中的文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\site packages\tensorflow\python\pywrap\u tensorflow\u internal.py”第20行
返回importlib.import\u模块(“pywrap\u tensorflow\u internal”)
文件“C:\Users\Manish\Anaconda3\envs\tensorflow gpu\lib\importlib\\uuuu init\uuuu.py”,第126行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
ModuleNotFoundError:没有名为“\u pywrap\u tensorflow\u internal”的模块
未能加载本机TensorFlow运行时。
看见https://www.tensorflow.org/install/install_sources#common_installation_problems
因为一些常见的原因和解决方案。包括