记录一下自己配置环境的过程,做个笔记。如果能帮到各位,我的荣幸。
第一步:检查自己电脑是否有gpu(注意:是nvidia的GPU),如果有,请参考以下网址安装安装Cuda与CuDNN:
https://blog.csdn.net/qq_23013309/article/details/103965619
第二步:本人喜欢用anaconda3,来管理自己的版本。所以在装好cuda和cudnn之后,下载anaconda:
Anaconda | The World's Most Popular Data Science Platform
第三步:在annaconda3中配置虚拟环境pytorch_gpu:
打开anaconda powershell prompt,创建虚拟环境
S1、创建虚拟环境:conda create --name pytorch_gpu(这里是虚拟环境的名字) python=3.7
S2、激活虚拟环境:conda activate pytorch_gpu
S3、使用清华镜像安装 pytorch
在Pytorch网站查询需要安装的版本:https://pytorch.org/get-started/locally/
然后在虚拟环境中 分别输入:
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 --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
复制路径“conda install pytorch torchvision cudatoolkit=10.2”,注意去掉后缀“-c pytorch”
安装成功标志:python(显示版本号)
import torch (不报错)
补充知识:(如何使用镜像安装)
pip install -i 镜像地址 pytorch==您想要的版本
镜像地址也不唯一:
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
第四步:使用pycharm编程
1、在官网上下载pycharm安装程序
2、新建工程
设置项目编译器
File---settings---project project interpreter
点击add
Existing environment:
interpretre路径:
anaconda路径---envs---虚拟环境--python.exe
第五步:如果喜欢jupyter notebook 编程 附上过程
参考:启动jupyter notebook配置虚拟环境_Haward-CSDN博客_jupyter notebook 虚拟环境
S1、在虚拟环境中安装jupyter notebook:
conda install ipykernel
S2、为虚拟环境下创建kernel文件:
conda install -n 环境名称 ipykernel
S3、激活conda环境: source activate 环境名称,将环境写入notebook的kernel中,
python -m ipykernel install --user --name 环境名称 --display-name "显示的名称"
如:
python -m ipykernel install --user --name tf_keras --display-name tf_keras
S4、打开notebook服务器:
jupyter notebook