找一个 demo.py ,执行,检验
参考:https://blog.csdn.net/geyunfei_/article/details/78782804
# 引入 tensorflow 模块
import tensorflow as tf
# 创建一个整型常量,即 0 阶 Tensor
t0 = tf.constant(3, dtype=tf.int32)
# 创建一个浮点数的一维数组,即 1 阶 Tensor
t1 = tf.constant([3., 4.1, 5.2], dtype=tf.float32)
# 创建一个字符串的2x2数组,即 2 阶 Tensor
t2 = tf.constant([['Apple', 'Orange'], ['Potato', 'Tomato']], dtype=tf.string)
# 创建一个 2x3x1 数组,即 3 阶张量,数据类型默认为整型
t3 = tf.constant([[[5], [6], [7]], [[4], [3], [2]]])
# 打印上面创建的几个 Tensor
print(t0)
print(t1)
print(t2)
print(t3)
执行 demo.py
>>>
==== RESTART: D:\下载\forGPU--CUDA--TensorFlow--CUDNN\tensorflow_demo_01.py ====
Traceback (most recent call last):
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\ProgramFiles\python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\ProgramFiles\python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\下载\forGPU--CUDA--TensorFlow--CUDNN\tensorflow_demo_01.py", line 2, in
import tensorflow as tf
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\__init__.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\ProgramFiles\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "D:\ProgramFiles\python36\lib\imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "D:\ProgramFiles\python36\lib\imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: 找不到指定的模块。
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.
>>>
D:\下载>pip install tensorflow
Collecting tensorflow
Downloading https://files.pythonhosted.org/packages/c1/e1/a5693a158f3867417d7b50bd0514c83304706242fae74463705b8c373777/tensorflow-1.11.0-cp36-cp36m-win_amd64.whl (46.9MB)
72% |███████████████████████ | 34.1MB 59kB/s eta 0:03:35Exception:
Traceback (most recent call last):
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\urllib3\response.py", line 331, in _error_catcher
yield
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\urllib3\response.py", line 413, in read
data = self._fp.read(amt)
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "d:\programfiles\python36\lib\http\client.py", line 449, in read
n = self.readinto(b)
File "d:\programfiles\python36\lib\http\client.py", line 493, in readinto
n = self.fp.readinto(b)
File "d:\programfiles\python36\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "d:\programfiles\python36\lib\ssl.py", line 1012, in recv_into
return self.read(nbytes, buffer)
File "d:\programfiles\python36\lib\ssl.py", line 874, in read
return self._sslobj.read(len, buffer)
File "d:\programfiles\python36\lib\ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\programfiles\python36\lib\site-packages\pip\_internal\cli\base_command.py", line 143, in main
status = self.run(options, args)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
resolver.resolve(requirement_set)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\resolve.py", line 102, in resolve
self._resolve_one(requirement_set, req)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\resolve.py", line 256, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\resolve.py", line 209, in _get_abstract_dist_for
self.require_hashes
File "d:\programfiles\python36\lib\site-packages\pip\_internal\operations\prepare.py", line 283, in prepare_linked_requirement
progress_bar=self.progress_bar
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 836, in unpack_url
progress_bar=progress_bar
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 673, in unpack_http_url
progress_bar)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 897, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 617, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "d:\programfiles\python36\lib\site-packages\pip\_internal\utils\hashes.py", line 48, in check_against_chunks
for chunk in chunks:
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 585, in written_chunks
for chunk in chunks:
File "d:\programfiles\python36\lib\site-packages\pip\_internal\utils\ui.py", line 159, in iter
for x in it:
File "d:\programfiles\python36\lib\site-packages\pip\_internal\download.py", line 574, in resp_read
decode_content=False):
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\urllib3\response.py", line 465, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "d:\programfiles\python36\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "d:\programfiles\python36\lib\site-packages\pip\_vendor\urllib3\response.py", line 336, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
D:\下载>
手动下载 tensorflow-1.11.0-cp36-cp36m-win_amd64.whl
https://pypi.org/project/tensorflow/#files
本地安装
pip install tensorflow-1.11.0-cp36-cp36m-win_amd64.whl
完成后再次运行 demo.py
>>>
==== RESTART: D:\下载\forGPU--CUDA--TensorFlow--CUDNN\tensorflow_demo_01.py ====
Tensor("Const:0", shape=(), dtype=int32)
Tensor("Const_1:0", shape=(3,), dtype=float32)
Tensor("Const_2:0", shape=(2, 2), dtype=string)
Tensor("Const_3:0", shape=(2, 3, 1), dtype=int32)
>>>
嗯,这个表明 tensorflow 安装成功了。
下个问题,如何检验 tensorflow-gpu 安装成功了?