在同一个虚拟环境中,安装pytorch和tensorflow
1.创建一个新的虚拟环境
conda create -n ten_py_8 python=3.8
2.进入虚拟环境中
conda activate ten_py_8
3.安装tensorflow
// conda create --prefix D:\Anaconda\envs\ten_py_8 python=3.8
// conda activate D:\Anaconda\envs\ten_py_8
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install protobuf==3.20.0
pip install numpy==1.19.5
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge cudnn=8.1.0.77
pip install tensorflow-gpu==2.6.0
pip install matplotlib==3.3.4
pip install scikit-learn==0.24.1
pip install pandas==1.2.0
pip install keras==2.6
pip install seaborn==0.9.0
pip install jupyter
cd D:\Anaconda\envs\ten_py_8\Scripts
python.exe -m ipykernel install --user --name=ten_py_8
pip install jupyterlab-language-pack-zh-CN
4.验证tensorflow的命令
import tensorflow as tf
print(tf.reduce_sum(tf.random.normal([1000, 1000])))
#output:tf.Tensor(871.0935, shape=(), dtype=float32)
5.安装pytorch
输入命令进行查找自己设备能够兼容的最大版本号
nvidia-smi
可以在官网进行查找安装,conda
不行就换pip
再不行就换pip3
,实在不行就换镜像,如下
命令+install
+直接是自己想要的版本号+-f
+网站(仓库)
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html
6.验证pytorch的命令
import torch
print(torch.cuda.is_available())
# output:True
7.验证结果
如果安装python=3.9,那么可能会出现有的包(spicy)版本较高,不支持把numpy改为1.19,这个时候可以安装较低版本的来避免冲突(比如pip install spicy==1.10
)
参考:
https://blog.youkuaiyun.com/zz3035786953/article/details/134937519
icy==1.10`)
参考:
https://blog.youkuaiyun.com/zz3035786953/article/details/134937519