Linux

Conda 管理环境

1. 创建虚拟环境

conda create -n env_name python=3.6
#env_name: 虚拟环境名称
#jupyter,ipython环境
conda install ipykernel
conda install -n 环境名称 ipykernel

2. 激活虚拟环境

#Linux:
source activate env_name

#Windows:
activate env_name

3. 保存环境

#导出env环境安装的所有package
conda env export > environment.yaml
#使用environment.yml创建环境
conda env create -f environment.yaml

4. 关闭虚拟环境

#Linux:
source deactivate 

#Windows:
deactivate

5. 列出环境

conda env list

6. 删除conda env环境

conda env remove -n env_name

python3测试GPU

  • 创建torch环境
conda create --name python_38-pytorch_1.7.0 python=3.8
conda activate python_38-pytorch_1.7.0
  • install torch

https://pytorch.org/get-started/locally/

import torch
flag = torch.cuda.is_available()
if flag:
    print("CUDA可使用")
else:
    print("CUDA不可用")

ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print("驱动为:",device)
print("GPU型号: ",torch.cuda.get_device_name(0))

评论

  1. Aksy
    Chrome 99

    pip install -r requirements.txt

This is just a placeholder img.