引自:https://blog.csdn.net/m0_63706703/article/details/138837331
打开终端,创建虚拟环境:
python3 -m venv env_name # (python3 -m 路径 环境名)
激活新的虚拟环境(linux终端):
source env_name/bin/activate
在新的虚拟环境安装对应的GPU版本pytorch
终端命令:
python3.7版本:pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117
python3.8及以后:pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
新开一个终端:输入python:import torch
,输入torch.__version__
检查torch版本是否正确安装:
# 如果需要进行持久化安装, 需要使用持久化路径, 如下方代码示例:
!mkdir /home/aistudio/external-libraries
!pip install beautifulsoup4 -t /home/aistudio/external-libraries
# 同时添加如下代码, 这样每次环境(kernel)启动的时候只要运行下方代码即可:
import sys
sys.path.append('/home/aistudio/external-libraries')
Conda常用指令
conda create -n fastreid python=3.7
conda activate fastreid
conda remove -n 需要删除的环境名 --all
conda config --remove-key channels #删除所有的channels
添加清华镜像源
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels http://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/cloud/bioconda/linux-64
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
vscode切换解释器:Ctrl+Shift+P打开命令框输入Python:Select Interpreter
pip换源
清华源
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
评论区