tensorflow 环境配置
安装Anaconda
参考如下链接:
Anaconda介绍、安装及使用教程
超全Anaconda(Python整合包)导修(图文详解)
安装Pycharm
下载一个社区版本即可
pycharm 下载地址
配置环境
启动Anaconda Powershell 工具
安装tensorflow
## 1. 本地创建一个tensorflow的目录,下载必备的软件包
(base) PS C:\Users\Administrator> conda creat -n TF2.1 python=3.7
## 2. 激活
(TF2.1) PS C:\Users\Administrator> conda activate TF2.1
## 3. 安装tensorflow
(TF2.1) PS C:\Users\Administrator> pip install tensorflow-gpu
## 4. 测试,是否加载成功
(TF2.1) PS C:\Users\Administrator> python
Python 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 01:53:57) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.3.0'
>>>
pycharm 工程里面选择编译器
这里指定要用自定义下载使用的python
测试用例
import tensorflow as tf
a = tf.ones([3,2])
b = tf.fill([2,3],3.)
print(tf.matmul(a,b))
if __name__=='__main__':
pass
测试结果
tf.Tensor(
[[6. 6. 6.]
[6. 6. 6.]
[6. 6. 6.]], shape=(3, 3), dtype=float32)
Process finished with exit code 0
遇到问题
- 如果遇到下载失败,将C:\Users\Administrator.condarc文件中的https改为http
- 将 - default删除
- 有些硬件不支持Nvidia的Cuda,因此有些资源是无法下载的,本机只下载的是CPU版本的;
ssl_verify: true
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
show_channel_urls: true