Tensorflow 安装和测试(Anaconda4.7.10+windows10)

一. 软件下载

二. 配置相关

1. 修改 Jupyter notebook 默认工作路径

  (1)打开 Anaconda Prompt ,输入 jupyter notebook --generate-config,打开文件 C:\Users\xxx\.jupyter\jupyter_notebook_config.py ,修改 c.NotebookApp.notebook_dir = 'G:\StudyFiles\PythonProjects'

  (2)修改快捷方式的启动路径

2. 配置conda镜像源(参考 https://blog.csdn.net/Sagepyt/article/details/100740862

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

3. conda常用的命令

 1)conda list 查看安装了哪些包。
    2)conda env list 或 conda info -e 查看当前存在哪些虚拟环境
    3)conda update conda 检查更新当前conda

4.创建python虚拟环境
conda create -n your_env_name python=X.X

5.删除虚拟环境
conda remove -n your_env_name(虚拟环境名称) --all

6.删除环境中的某个包
conda remove --name your_env_name  package_name

7.jupyter-notebook添加python虚拟环境
conda install -n tensorflow ipykernel

8.生成ipykernel的配置文件(–name之后跟的是在jupyter-notebook中对应虚拟环境的kernel名称)
python -m ipykernel install --name tensorflow-notebook

9.测试代码

import tensorflow as tf
tf.compat.v1.disable_eager_execution()   # The Session graph is empty.  Add operations to the graph before calling run().
sess = tf.compat.v1.Session()
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)
result = sess.run(product)
print(result)

 

posted on 2020-04-03 15:02  积跬步---行千里  阅读(354)  评论(0编辑  收藏  举报