主要参考了以下几篇文章:
『TensorFlow2.0正式版教程』极简安装TF2.0正式版(CPU&GPU)教程
CUDA driver version is insufficient for CUDA runtime version
AttributeError: module 'tensorflow' has no attribute 'placeholder'等问题的解决
参考第1篇文章,很快安装好了TF2.0 CPU 版本,测试也OK。记录一下:
windows推荐地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.7.10-Windows-x86_64.exe
conda create -n TF_2C python=3.6
conda activate TF_2C
pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
因为我的笔记本有Nvidia GPU,于是手痒痒想继续装个TF2.0 GPU版本试试,结果失败了。出现“CUDA driver version is insufficient for CUDA runtime version”错误。网上搜索了下,这是因为CUDA driver 和 run time lib 不匹配所致,可以参考第2/3篇文章的解决方案。但是,看到安装包这么大,又担心节外生枝,尝试了几次,就放弃了。
参考第4篇文章,更新了conda为国内源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
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/msys2/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
注意,可以在安装Python Package的时候,使用国内源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xxx
安装好后就可以在cmd中使用conda指令了,cmd打开方式,windows键+R键,弹出输入框,输入cmd就进入了。也可以直接在windows搜索cmd点击运行。
下面介绍些cmd conda指令:
- 查看conda环境:conda env list
- 新建conda环境(env_name就是创建的环境名,可以自定义):conda create -n env_name
- 激活conda环境(ubuntu与Macos 将conda 替换为source):conda activate env_name
- 退出conda环境:conda deactivate
- 安装和卸载python包:conda install numpy # conda uninstall numpy
- 查看已安装python列表:conda list -n env_name