【深度学习 走进tensorflow2.0】linux 下 tensorflow 2.0 环境安装

无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。
人工智能教程

安装python 环境,均以python3.7版本、可用anaconda 安装

conda create -n tf2 python=3.7

进入名为“tf2”的虚拟环境

source  activate tf2             

使用 Python 包管理器 pip 安装 TensorFlow。在命令行下输入:

pip install tensorflow==2.0.0           # TensorFlow CPU版本
pip install tensorflow-gpu==2.0.0       # TensorFlow GPU版本,需要具有NVIDIA显卡及正确安装驱动程序

或者使用 清华镜像 安装 会比较快哦

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  tensorflow_gpu==2.0.0

在国内环境下,推荐使用国内的 pypi 镜像和 Anaconda 镜像,将显著提升 pip 和 conda 的下载速度;

清华大学的 pypi 镜像:https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
清华大学的 Anaconda 镜像:https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

conda 常用命令:

conda create --name [env-name]      # 建立名为[env-name]的Conda虚拟环境
conda activate [env-name]           # 进入名为[env-name]的Conda虚拟环境
conda deactivate                    # 退出当前的Conda虚拟环境
conda env remove --name [env-name]  # 删除名为[env-name]的Conda虚拟环境
conda env list                      # 列出所有Conda虚拟环境

安装完毕后,我们来编写一个简单的程序来验证安装。

import tensorflow as tf

A = tf.constant([[1, 2], [3, 4]])
B = tf.constant([[5, 6], [7, 8]])
C = tf.matmul(A, B)

print(C)

如果能够最终输出:

tf.Tensor(
[[19 22]
[43 50]], shape=(2, 2), dtype=int32)

说明 TensorFlow 已安装成功。运行途中可能会输出一些 TensorFlow 的提示信息,属于正常现象。

在这里插入图片描述

在这里插入图片描述

大功告成!

已标记关键词 清除标记
安装代码:sudo pip install tensorflow==2.0.0-beta0 问题描述如下: ``` ERROR: Exception: Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/response.py", line 425, in _error_catcher yield File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/response.py", line 507, in read data = self._fp.read(amt) if not fp_closed else b"" File "/usr/lib/python3.6/http/client.py", line 459, in read n = self.readinto(b) File "/usr/lib/python3.6/http/client.py", line 503, in readinto n = self.fp.readinto(b) File "/usr/lib/python3.6/socket.py", line 586, in readinto return self._sock.recv_into(b) File "/usr/lib/python3.6/ssl.py", line 1012, in recv_into return self.read(nbytes, buffer) File "/usr/lib/python3.6/ssl.py", line 874, in read return self._sslobj.read(len, buffer) File "/usr/lib/python3.6/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 "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 188, in _main status = self.run(options, args) File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/req_command.py", line 185, in wrapper return func(self, options, args) File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 333, in run reqs, check_supported_wheels=not options.target_dir File "/usr/local/lib/python3.6/dist-packages/pip/_internal/resolution/legacy/resolver.py", line 179, in resolve discovered_reqs.extend(self._resolve_one(requirement_set, req)) File "/usr/local/lib/python3.6/dist-packages/pip/_internal/resolution/legacy/resolver.py", line 362, in _resolve_one abstract_dist = self._get_abstract_dist_for(req_to_install) File "/usr/local/lib/python3.6/dist-packages/pip/_internal/resolution/legacy/resolver.py", line 314, in _get_abstract_dist_for abstract_dist = self.preparer.prepare_linked_requirement(req) File "/usr/local/lib/python3.6/dist-packages/pip/_internal/operations/prepare.py", line 469, in prepare_linked_requirement hashes=hashes, File "/usr/local/lib/python3.6/dist-packages/pip/_internal/operations/prepare.py", line 259, in unpack_url hashes=hashes, File "/usr/local/lib/python3.6/dist-packages/pip/_internal/operations/prepare.py", line 130, in get_http_url link, downloader, temp_dir.path, hashes File "/usr/local/lib/python3.6/dist-packages/pip/_internal/operations/prepare.py", line 281, in _download_http_url for chunk in download.chunks: File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/progress_bars.py", line 166, in iter for x in it: File "/usr/local/lib/python3.6/dist-packages/pip/_internal/network/utils.py", line 39, in response_chunks decode_content=False, File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/response.py", line 564, in stream data = self.read(amt=amt, decode_content=decode_content) File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/response.py", line 529, in read raise IncompleteRead(self._fp_bytes_read, self.length_remaining) File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.6/dist-packages/pip/_vendor/urllib3/response.py", line 430, 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. ``` 求解决方法
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页