cannot run tensorflow in windows 10
我使用cmd命令在Windows 10上成功安装了tensorflow:
1 | pip3 install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0-py3-none-any.whl |
但是,当我使用PyCharm运行一个简单的代码时,例如:
1 2 3 4 | import tensorflow as tf node1 = tf.constant(3.0, dtype=tf.float32) node2 = tf.constant(4.0) # also tf.float32 implicitly print(node1, node2) |
我在控制台上收到以下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | Traceback (most recent call last): File"C:\Users ame\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 ame\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 ame\Desktop\Desktop\lib\site- packages\tensorflow\python\__init__.py", line 66, in <module> from tensorflow.python import pywrap_tensorflow File"C:\Users ame\Desktop\Desktop\lib\site- packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module> _pywrap_tensorflow = swig_import_helper() File"C:\Users ame\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 ame\Desktop\Desktop\lib\site- packages\tensorflow\__init__.py", line 24, in <module> from tensorflow.python import * File"C:\Users ame\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 ame\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 ame\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 ame\Desktop\Desktop\lib\site- packages\tensorflow\python\__init__.py", line 66, in <module> from tensorflow.python import pywrap_tensorflow File"C:\Users ame\Desktop\Desktop\lib\site- packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module> _pywrap_tensorflow = swig_import_helper() File"C:\Users ame\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.