深度学习基础(环境篇)
虚拟环境
-
新建虚拟环境
conda create -n nlp python=3.6-
报错1:(果真用的久什么问题都能碰到)
Solving environment: failed CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/free/noarch/repodata.json.bz2> Elapsed: - An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way. If your current network has https://www.anaconda.com blocked, please file a support request with your network engineering team. SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/free/noarch/repodata.json.bz2 (Caused by SSLError(SSLError("bad handshake: Error([(\'SSL routines\', \'ssl3_get_server_certificate\', \'certificate verify failed\')])")))'))描述:未开代理,使用公司网络/热点均出现以上错误,直接访问(已解决)https://repo.anaconda.com/pkgs/free/noarch/repodata.json.bz2没问题。
解决:参考链接 本次使用是windows,实测有效。
CMD进入%HOMEPATH%(即C:/USER/),找到.condrac文件,以记事本等任意可以修改的编辑器打开。- 将
- https://…改成- http://…,ssl_verify: false,保存退出。
-
报错2:
Collecting package metadata(current repodata.json): failed COndaHTTPErrOr: HTTP 429 TO0 MANY REQUESTS for url <https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64/current repodata.json>Elapsed:00:46.251752 An HTTP error occurred when trying to retrieve this URL.HTTP errors are often intermittent, and a simple retry will get you on your way https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64描述:ubuntu 20.04终端创建出现问题(已解决)
解决:参考链接 推测是
conda源加入了不知名的URL,现在不能使用了(或者废弃)。于是进入conda镜像源文件将相关废弃源删除。vim ~/.condarc- 移动光标
dd将https://mirrors.ustc.edu.cn相关源全部删除
-
-
虚拟环境的常见操作
# 创建python虚拟环境 conda create -n wkkk python=3.9 # 激活虚拟环境 activate wkkk # 查看当前存在哪些虚拟环境 conda env list conda info -e # 查看安装了哪些包 conda list # 检查更新当前conda conda update conda # 删除某个虚拟环境 conda remove --name wkkk --all -
anaconda镜像源添加
# 清华源 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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r 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.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 --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ # 设置搜索时显示通道地址 conda config --set show_channel_urls yes # 查看已安装的源 conda config --show-sources -
陆续碰到的conda报错
(nlp) C:\Users\15520>conda install -c huggingface transformers Solving environment: failed InvalidVersionSpecError: Invalid version spec: =2.7anaconda的版本太低,conda的版本也低==,仍然采用pip,下次一定
-
pip换源
-
临时换源
# 清华源 pip install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple # 阿里源 pip install xxxx -i https://mirrors.aliyun.com/pypi/simple/ # 腾讯源 pip install xxxx -i http://mirrors.cloud.tencent.com/pypi/simple # 豆瓣源 pip install xxxx -i http://pypi.douban.com/simple/ -
永久换源
# 清华源 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 阿里源 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ # 腾讯源 pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple # 豆瓣源 pip config set global.index-url http://pypi.douban.com/simple/ -
换回原有的源
pip config unset global.index-url
-
-
pip常见的操作
-
清楚缓存
pip cache purge -
更新pip和setuptools
pip install --upgrade pip setuptools
-
CUDA和Cudnn安装
之前写的内容还挺详细OTZ
Torch安装
-
查看CUDA版本
-
nvcc-V:显示当前安装的CUDA版本
-
nvidia-smi:显示当前系统支持的最大CUDA版本
-
-
去torch官网找到对应CUDA一致的Torch版本
Previous PyTorch Versions | PyTorch
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 -c pytorchTorch与python好像有对应,python3.6支持到torch10(没记错的话)
-
检查torch是否安装成功
import torch print(torch.__version__) print(torch.version.cuda) print(torch.backends.cudnn.version()) print('gpu',torch.cuda.is_available())
使用时的一些Tips
-
动态刷新查看当前显存
watch -n 0.5 nvidia-smi -
安装
pip install transformers时,python3.6失败,python3,7成功。 -
安装
torchtext,需要十分注意与torch的版本,否则会存在不兼容的现象。计算公式:
pytorch为1.a.b,则torchtext版本应该是0.a+1.beg:
pytorch版本是1.12.1,对应的torchtext版本应该是0.13.1
本文介绍了深度学习的基础环境配置,包括虚拟环境的创建与管理,CUDA和Cudnn的安装,以及Torch的安装步骤。在虚拟环境中遇到的网络访问问题和Ubuntu终端创建问题提供了解决方案。还分享了conda和pip的换源操作,以及如何动态查看GPU显存和处理版本兼容性问题。
9748

被折叠的 条评论
为什么被折叠?



