确保显卡驱动都是正常运行的(无安装显卡驱动,需先安装显卡驱动)
首先在 anaconda官网 安装python3.7version
双击anaconda安装包,引导安装,同意下一步,安装想要安装的目录下,然后需要勾选(上下都是钩)将anaconda加入环境变量,完成安装 conda create -n pytorch python=3.7
然后在开始菜单栏里面找到anaconda Prompt(Anaconda3)打开,新建一个名叫TF2.1的环境变量(conda create -n TF2.1 python=3.7) 安装相应的包 然后进入conda2.1环境(conda activate TF2.1)
然后安装英伟达的SDK10.1版本,即cuda(conda install cudatoolkit=10.1)
然后安装英伟达深度学习软件包7.6版本,(conda install cudnn=7.6)
如果以上两步报错,说明电脑不支持英伟达,跳过,直接安装tesorflow,(pip install tensorflow==2.1)
安装完成后,
我们继续在命令行输入python回车
输入import tensorflow as tf回车
输入tf.__version__ 如果显示2.1.0则说明安装成功了
pytorch的版本选择网站在https://pytorch.org/get-started/locally/
pytorch的安装包链接:https://download.pytorch.org/whl/torch_stable.html
安装cpu版本的pytorch cpu/torch-1.6.0%2Bcpu-cp37-cp37m-win_amd64.whl
pip install --default-time=300 https://download.pytorch.org/whl/cpu/torch-1.6.0%2Bcpu-cp37-cp37m-win_amd64.whl
pip install --default-time=300 https://download.pytorch.org/whl/cpu/torchvision-0.7.0%2Bcpu-cp37-cp37m-win_amd64.whl
cpu/torchvision-0.7.0%2Bcpu-cp37-cp37m-win_amd64.whl
验证:命令输入import torch
print(torch.__version__)
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com 后跟安装的包
# 添加清华镜像
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/
# 添加pytorch镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --set show_channel_urls yes
安装cpu版本
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
pytorch版本的gpu版本
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch 10.1换成其他版本
pip install torch===1.7.1+cu110 torchvision===0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
-i https://pypi.tuna.tsinghua.edu.cn/simple
conda - info - e 查询变量环境
pip install --default-time=300 https://download.pytorch.org/whl/cpu/torchvision-0.7.0%2Bcpu-cp37-cp37m-win_amd64.whl
直接跟安装网址
安装不上可以看这个
镜像源:-i https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/
接下来在官网下载pycharm集成开发环境,社区版本,双击安装包,左边三个选项根据个人喜好,可都选,右边一框是环境变量,要勾上,最后选Reboot now重启电脑 完成安装
重启后打开pycharm,新建工程,文件放在你想放的地方,最好在C盘之外新建一个pycharm文件存放,
点project interpreter New Virtualenv environment设置环境变量 点Existing interpreter中选择使用刚刚配置好的conda环境,interpreter选择TF2.1中的python作为解释器。create,新建工程。
pip install tensorflow==2.1 -i https://mirrors.aliyun.com/pypi/simple/
完成安装
pip install tensorflow-cpu==2.1 -i https://mirrors.aliyun.com/pypi/simple/
-i https://pypi.tuna.tsinghua.edu.cn/simple
在Anaconda Prompt中输入命令行:activate tensorflow # 激活tensorflow环境
pip list # 查看tensorflow环境下的所有安装包
pip uninstall tensorflow # 卸载
这两行命令多操作几次直到提示不存在tensorflow为止
,把它们都先卸载,进入目录F:\anaconda\envs\tensorflow\Lib\site-packages(tensorflow安装路径)删除与tensorflow相关的所有文件夹(tensorboard、tensorflow_estimator等等),至此,tensorflow完全卸载干净。
安装前要对应版本号 ,已经安装的版本查看可以输入以下命令,
pytorch的查看
import torch
print("Pytorch version:")
print(torch.__version__)
print("CUDA Version: ")
print(torch.version.cuda)
print("cuDNN version is :")
print(torch.backends.cudnn.version())
print(torch.cuda.is_available())
print(torch.cuda.is_available())
tenforflow查看
print("tf version:")
print(tf.__version__)
print("CUDA Version: ")
print(tf.version.cuda)
print("cuDNN version is :")
print(tf.backends.cudnn.version())
python版本
import sys
print("当前python版本", sys.version)
import tensorflow
安装pytorch
v1.8.0
Linux and Windows
# CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly -c pytorch
Wheel
# RocM 4.0.1 (Linux only)
pip install torch -f https://download.pytorch.org/whl/rocm4.0.1/torch_stable.html
pip install ninja
pip install 'git+https://github.com/pytorch/vision.git@v0.9.0'
# CUDA 11.0
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
# CPU only
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
v1.7.1
Linux and Windows
# CUDA 9.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch
# CUDA 10.1
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch
# CUDA 10.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2 -c pytorch
# CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch
# CPU Only
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cpuonly -c pytorch
Wheel
# CUDA 11.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2
# CUDA 10.1
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 9.2
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
# CPU only
pip install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
v1.5.1
# CUDA 9.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=9.2 -c pytorch
# CUDA 10.1
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1 -c pytorch
# CUDA 10.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2 -c pytorch
# CPU Only
conda install pytorch==1.5.1 torchvision==0.6.1 cpuonly -c pytorch
# CUDA 10.2
pip install torch==1.5.1 torchvision==0.6.1
# CUDA 10.1
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 9.2
pip install torch==1.5.1+cu92 torchvision==0.6.1+cu92 -f https://download.pytorch.org/whl/torch_stable.html
# CPU only
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
print(tensorflow.__file__)#当前文件安装位置