首页 > Windows开发 > 详细

通过pip 安装 TensorFlow Windows10 安装笔记

时间:2020-02-22 16:30:19      阅读:2341      评论:0      收藏:0      [点我收藏+]

* 安装前建议先阅读官方文档,了解操作系统及Python版本要求

  官网:https://www.tensorflow.org/install

  当前最新Python版本为3.8.1,但TensorFlow 目前只支持到3.7 

 ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
 ERROR: No matching distribution found for tensorflow

如上所示的错误,就是我用Python3.8.1安装所遇到的问题。

技术分享图片

 

 检查Python、pip、virtualenv是否已配置,若已存在则跳过基础安装

python3 --version
pip3 --version
virtualenv --version

开始安装:

1.下载Python3.7 

  官网:https://www.python.org/downloads/

  安装Python时勾选配置环境变量,若不勾,需要手动配置。

技术分享图片

安装完成验证:

PS D:\GitHupRepo\tensorflow> python --version
Python 3.7.6

 

2. pip3 --version 确认pip是否已包含在Python安装,若没有则手动操作

 下载get-pip.py 脚本,两种方式:1.链接:https://bootstrap.pypa.io/get-pip.py ,或者通过curl,没有curl命令的需要安装。

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

get-pip.py 脚本文件夹位置,运行Pthon命令

python get-pip.py

验证pip

PS D:\GitHupRepo\tensorflow> pip3 --version
pip 20.0.2 from d:\program files\python\python37\lib\site-packages\pip (python 3.7)

pip安装文档:https://pip.pypa.io/en/stable/installing/

 

3.安装  virtualenv

PS D:\GitHupRepo\tensorflow> pip3 install -U pip virtualenv

 

4.创建虚拟环境

PS D:\GitHupRepo\tensorflow> virtualenv --system-site-packages -p python3 ./venv
PS D:\GitHupRepo\tensorflow> .\venv\Scripts\activate

我在PowerShell上运行.\venv\Scripts\activate 的时候报错,无法加载文件  \venv\scripts\activate.ps1

这是由于操作系统不允许PowerShell执行脚本导致,解决办法:

以管理员身份重新打开PowerShell,执行

Set-ExecutionPolicy -ExecutionPolicy UNRESTRICTED

 开启脚本运行权限。然后输入A ,选择全是。

参考文档:https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7

技术分享图片

 

 

重新运行命令:

PS D:\GitHupRepo\tensorflow> .\venv\Scripts\activate
(venv) PS D:\GitHupRepo\tensorflow>

升级pip

(venv) PS D:\GitHupRepo\tensorflow> pip install --upgrade pip
Requirement already up-to-date: pip in d:\githuprepo\tensorflow\venv\lib\site-packages (20.0.2)
(venv) PS D:\GitHupRepo\tensorflow>

 

5.安装TensorFlow 

pip install --upgrade tensorflow
(venv) PS D:\GitHupRepo\tensorflow> pip install --upgrade tensorflow
Collecting tensorflow
  Downloading tensorflow-2.1.0-cp37-cp37m-win_amd64.whl (355.8 MB)
     |████████████████████████████████| 355.8 MB 1.6 MB/s
Collecting tensorflow-estimator<2.2.0,>=2.1.0rc0
  Downloading tensorflow_estimator-2.1.0-py2.py3-none-any.whl (448 kB)
     |████████████████████████████████| 448 kB 262 kB/s
Collecting opt-einsum>=2.3.2
  Downloading opt_einsum-3.1.0.tar.gz (69 kB)
     |████████████████████████████████| 69 kB 4.5 MB/s
Collecting keras-preprocessing>=1.1.0
  Downloading Keras_Preprocessing-1.1.0-py2.py3-none-any.whl (41 kB)
     |████████████████████████████████| 41 kB ...
Collecting grpcio>=1.8.6
  Downloading grpcio-1.27.2-cp37-cp37m-win_amd64.whl (1.9 MB)
     |████████████████████████████████| 1.9 MB ...
Collecting google-pasta>=0.1.6
  Downloading google_pasta-0.1.8-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 787 kB/s
Collecting keras-applications>=1.0.8
  Downloading Keras_Applications-1.0.8-py3-none-any.whl (50 kB)
     |████████████████████████████████| 50 kB 3.0 MB/s
Collecting numpy<2.0,>=1.16.0
  Downloading numpy-1.18.1-cp37-cp37m-win_amd64.whl (12.8 MB)
     |████████████████████████████████| 12.8 MB 1.1 MB/s
Collecting gast==0.2.2
  Downloading gast-0.2.2.tar.gz (10 kB)
Collecting termcolor>=1.1.0
  Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Requirement already satisfied, skipping upgrade: six>=1.12.0 in d:\program files\python\python37\lib\site-packages (from tensorflow) (1.14.0)
Collecting wrapt>=1.11.1
  Downloading wrapt-1.12.0.tar.gz (27 kB)
Collecting astor>=0.6.0
  Downloading astor-0.8.1-py2.py3-none-any.whl (27 kB)
Requirement already satisfied, skipping upgrade: wheel>=0.26; python_version >= "3" in d:\githuprepo\tensorflow\venv\lib\site-packages (from tensorflow) (0.34.2)
Collecting tensorboard<2.2.0,>=2.1.0
  Downloading tensorboard-2.1.0-py3-none-any.whl (3.8 MB)
     |████████████████████████████████| 3.8 MB 1.6 MB/s
Collecting protobuf>=3.8.0
  Downloading protobuf-3.11.3-cp37-cp37m-win_amd64.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 435 kB/s
Collecting scipy==1.4.1; python_version >= "3"
  Downloading scipy-1.4.1-cp37-cp37m-win_amd64.whl (30.9 MB)
     |████████████████████████████████| 30.9 MB 595 kB/s
Collecting absl-py>=0.7.0
  Downloading absl-py-0.9.0.tar.gz (104 kB)
     |████████████████████████████████| 104 kB 211 kB/s
Collecting h5py
  Downloading h5py-2.10.0-cp37-cp37m-win_amd64.whl (2.5 MB)
     |████████████████████████████████| 2.5 MB 544 kB/s
Collecting google-auth<2,>=1.6.3
  Downloading google_auth-1.11.2-py2.py3-none-any.whl (76 kB)
     |████████████████████████████████| 76 kB 1.7 MB/s
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Downloading google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB)
Collecting requests<3,>=2.21.0
  Downloading requests-2.23.0-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB ...
Collecting markdown>=2.6.8
  Downloading Markdown-3.2.1-py2.py3-none-any.whl (88 kB)
     |████████████████████████████████| 88 kB 2.0 MB/s
Collecting werkzeug>=0.11.15
  Downloading Werkzeug-1.0.0-py2.py3-none-any.whl (298 kB)
     |████████████████████████████████| 298 kB 939 kB/s
Requirement already satisfied, skipping upgrade: setuptools>=41.0.0 in d:\githuprepo\tensorflow\venv\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (45.2.0)
Collecting rsa<4.1,>=3.1.4
  Downloading rsa-4.0-py2.py3-none-any.whl (38 kB)
Collecting pyasn1-modules>=0.2.1
  Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
     |████████████████████████████████| 155 kB 595 kB/s
Collecting cachetools<5.0,>=2.0.0
  Downloading cachetools-4.0.0-py3-none-any.whl (10 kB)
Collecting requests-oauthlib>=0.7.0
  Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2019.11.28-py2.py3-none-any.whl (156 kB)
     |████████████████████████████████| 156 kB 6.4 MB/s
Collecting chardet<4,>=3.0.2
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 731 kB/s
Collecting idna<3,>=2.5
  Downloading idna-2.9-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 563 kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Downloading urllib3-1.25.8-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 1.1 MB/s
Collecting pyasn1>=0.1.3
  Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 5.5 MB/s
Collecting oauthlib>=3.0.0
  Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
     |████████████████████████████████| 147 kB 3.3 MB/s
Building wheels for collected packages: opt-einsum, gast, termcolor, wrapt, absl-py
  Building wheel for opt-einsum (setup.py) ... done
  Created wheel for opt-einsum: filename=opt_einsum-3.1.0-py3-none-any.whl size=61702 sha256=4faa14ea843d48963a92f115a8dd3a27803514ad8d5954087c5886553e730370
  Stored in directory: c:\users\wuj\appdata\local\pip\cache\wheels\21\e3\31\0d3919995e859eff01713d381aac3b6b43c69915a2942e5c65
  Building wheel for gast (setup.py) ... done
  Created wheel for gast: filename=gast-0.2.2-py3-none-any.whl size=7547 sha256=fe7ed3dfae06b57872a6e70e5a4a4781d2a3ffe8a69234943c5722c5fee771f5
  Stored in directory: c:\users\wuj\appdata\local\pip\cache\wheels\21\7f\02\420f32a803f7d0967b48dd823da3f558c5166991bfd204eef3
  Building wheel for termcolor (setup.py) ... done
  Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4835 sha256=ee9b67e7d512d20044b506ea87924d7bf5f3199c54bf289d23f30aa594caca87
  Stored in directory: c:\users\wuj\appdata\local\pip\cache\wheels\3f\e3\ec\8a8336ff196023622fbcb36de0c5a5c218cbb24111d1d4c7f2
  Building wheel for wrapt (setup.py) ... done
  Created wheel for wrapt: filename=wrapt-1.12.0-py3-none-any.whl size=19565 sha256=fd391c9d1365055e046ba6441af3d5171d0b62e72b88c41a6c7e01d09eac3842
  Stored in directory: c:\users\wuj\appdata\local\pip\cache\wheels\e5\78\69\f40ab7cae531c8f07003a9d1b4b81ebec14cda95519c57e7dd
  Building wheel for absl-py (setup.py) ... done
  Created wheel for absl-py: filename=absl_py-0.9.0-py3-none-any.whl size=121935 sha256=1ad603e2fb5b1bea2a79813a7c0eaa3e8f2d07ee81b54422c9ab8e70e3343a69
  Stored in directory: c:\users\wuj\appdata\local\pip\cache\wheels\cc\af\1a\498a24d0730ef484019e007bb9e8cef3ac00311a672c049a3e
Successfully built opt-einsum gast termcolor wrapt absl-py
Installing collected packages: tensorflow-estimator, numpy, opt-einsum, keras-preprocessing, grpcio, google-pasta, h5py, keras-applications, gast, termcolor, wrapt, astor, pyasn1, rsa, pyasn1-modules, cachetools, google-auth, oauthlib, certifi, chardet, idna, urllib3, requests, requests-oauthlib, google-auth-oauthlib, markdown, absl-py, werkzeug, protobuf, tensorboard, scipy, tensorflow
Successfully installed absl-py-0.9.0 astor-0.8.1 cachetools-4.0.0 certifi-2019.11.28 chardet-3.0.4 gast-0.2.2 google-auth-1.11.2 google-auth-oauthlib-0.4.1 google-pasta-0.1.8 grpcio-1.27.2 h5py-2.10.0 idna-2.9 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 numpy-1.18.1 oauthlib-3.1.0 opt-einsum-3.1.0 protobuf-3.11.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.23.0 requests-oauthlib-1.3.0 rsa-4.0 scipy-1.4.1 tensorboard-2.1.0 tensorflow-2.1.0 tensorflow-estimator-2.1.0 termcolor-1.1.0 urllib3-1.25.8 werkzeug-1.0.0 wrapt-1.12.0
(venv) PS D:\GitHupRepo\tensorflow>

切换到Python环境,导入tensorflow 验证,GPU报错可忽略:

(venv) PS D:\GitHupRepo\tensorflow> python
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-02-22 15:29:42.456736: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic libr
ary ‘cudart64_101.dll‘; dlerror: cudart64_101.dll not found
2020-02-22 15:29:42.460141: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do
not have a GPU set up on your machine.
>>>

 

 

至此,在windows10上通过pip 安装 TensorFlow就完成了!

 

参考链接:https://www.tensorflow.org/install/pip?lang=python3

通过pip 安装 TensorFlow Windows10 安装笔记

原文:https://www.cnblogs.com/aGameOfCode/p/12345666.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!