anaconda下 安装tensorflow2.0.0

一、首先,在cmd或者anaconda prompt中添加清华源

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. 测试

anaconda promp界面
执行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步和第3步具体如下:
anaconda prompt界面

以后需要使用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/

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值