一、首先,在cmd中添加清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

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/cloud/pytorch/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/

设置搜索时显示通道地址

conda config --set show_channel_urls yes

二、然后,进入anaconda prompt

  1. 创建Python虚拟环境。
conda create -n tensorflow python=3.7
  1. 进入虚拟环境
conda activate tensorflow
  1. 查看python版本
python --version
  1. 查看当前存在哪些虚拟环境
conda info --envs
  1. 安装tensorflow
pip install tensorflow==2.0.0 -i https://pypi.doubanio.com/simple/
  1. 测试

执行exit() 退出python

  1. 关闭虚拟环境
conda deactivate

8.使用命令 pip list 或者 conda list 查看安装了哪些包

——————–分割线——————–
一些错误
ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed.
CondaError: Downloaded bytes did not match Content-Length
RuntimeError: The current Numpy installation

三、jupyter

当我们用Anaconda自带的jupyter notebook中输入 import tensorflow as tf 的时候会失败,显示如下No module named ‘tensorflow’,原因是我们没有在TensorFlow的环境下打开它们。
为此,我们需要在TensorFlow环境下安装jupyter

  1. 在anaconda prompt中激活tensorflow
conda activate tensorflow
  1. 在tensorflow环境中安装jupyter
pip install jupyter -i https://pypi.doubanio.com/simple/
  1. 在tensorflow环境中进入jupyter
jupyter notebook

第1步和第2步具体如下:

以后需要使用tensorflow的时候都需要在 anaconda prompt 中像图示这样操作,才能在jupyter中正常使用tensorflow。

  1. 进入jupyter 后,用以下代码测试
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.Session()
a=tf.constant(1)
b=tf.constant(2)
print(sess.run(a+b))

应该是能运行出来了。

镜像办法:

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

注意以上格式为:pip install 你要的tensorflow版本号 -i 镜像网址

镜像网址包括:

清华:https://pypi.tuna.tsinghua.edu.cn/simple/

豆瓣:https://pypi.doubanio.com/simple/

本文地址:https://blog.csdn.net/weixin_45104871/article/details/111980129