python-3.x - 无法在 Windows 10 中运行 Tensorflow

标签 python-3.x machine-learning tensorflow

我使用cmd命令在Windows 10上成功安装了tensorflow:

pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl

但是,当我使用 PyCharm 运行简单的代码时,例如:

 import tensorflow as tf
 node1 = tf.constant(3.0, dtype=tf.float32)
 node2 = tf.constant(4.0) # also tf.float32 implicitly
 print(node1, node2)

我在控制台上收到以下错误:

  Traceback (most recent call last):
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 18, in 
  swig_import_helperfp, pathname, description = 
  imp.find_module('_pywrap_tensorflow', [dirname(__file__)])
  File "C:\Users\Name\Desktop\Desktop\lib\imp.py", line 296, in find_module
  raise ImportError(_ERR_MSG.format(name), name=name)
  ImportError: No module named '_pywrap_tensorflow'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\__init__.py", line 66, in <module>
  from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
  _pywrap_tensorflow = swig_import_helper()
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 20, in 
  swig_import_helper
  import _pywrap_tensorflow
  ModuleNotFoundError: No module named '_pywrap_tensorflow'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
  File "C:/Users/Name/Desktop/Desktop/ML/tfbasics.py", line 1, in <module>
  import tensorflow as tf
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\__init__.py", line 24, in <module>
  from tensorflow.python import *
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\__init__.py", line 72, in <module>
  raise ImportError(msg)
  ImportError: Traceback (most recent call last):
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 18, in 
  swig_import_helper
  fp, pathname, description = imp.find_module('_pywrap_tensorflow', 
  [dirname(__file__)])
  File "C:\Users\Name\Desktop\Desktop\lib\imp.py", line 296, in find_module
  raise ImportError(_ERR_MSG.format(name), name=name)
  ImportError: No module named '_pywrap_tensorflow'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\__init__.py", line 66, in <module>
  from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
   _pywrap_tensorflow = swig_import_helper()
  File "C:\Users\Name\Desktop\Desktop\lib\site-
  packages\tensorflow\python\pywrap_tensorflow.py", line 20, in 
  swig_import_helper
  import _pywrap_tensorflow
  ModuleNotFoundError: No module named '_pywrap_tensorflow'

我研究了网络来修复这个错误,但发现相互矛盾的结果没有帮助。任何人都可以指出为什么会出现此错误?

最佳答案

我不知道当你想在 Windows 上运行它时为什么使用 Mac

pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl

来自手册

Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:

(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.3.0-cp35-cp35m-win_amd64.whl To install the GPU version of TensorFlow, enter the following command (on a single line):

(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.3.0-cp35-cp35m-win_amd64.whl

也请不要忘记

TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you'll use to install TensorFlow.

关于python-3.x - 无法在 Windows 10 中运行 Tensorflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838282/

相关文章:

Python 3、以太坊——如何发送 ERC20 代币?

python - 为什么我再次执行时confusion_matrix不一样?

python - 高斯过程中 'Tensor is unhashable' 的 tensorflow 概率错误

machine-learning - 分布式运行 TensorFlow 时,多个参数服务器不会分担负载

python - 安装Python 3.8.1 --with-openssl --without-root/apt/yum

python-3.x - 无法成功比较两个字符串

machine-learning - Keras:引入批量标准化后 NaN 训练损失

validation - 如何根据混淆矩阵计算 K 交叉验证的最终指标?

python - 当我从 tensorflow 数据集中打印印地文文本时获取编码输出

python - 不可哈希类型,从集合中删除重复项但保留条目顺序