1. 创建环境

conda create -n pytorch1.7.1 python=3.7

2. 安装pytorch

安装pytorch官网上面安装指令https://pytorch.org/get-started/previous-versions/

conda install pytorch==1.7.1 torchvision==0.8.2  cudatoolkit=11.0 -c pytorch  ##torchaudio==0.7.2  语言的不需要

import torch的时候报错

(pytorch1.7.1) admin@admin-System-Product-Name:~$ python
Python 3.7.16 (default, Jan 17 2023, 22:20:44) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/media/algo/data_1/software/anconda_install/envs/pytorch1.7.1/lib/python3.7/site-packages/torch/__init__.py", line 189, in <module>
    _load_global_deps()
  File "/media/algo/data_1/software/anconda_install/envs/pytorch1.7.1/lib/python3.7/site-packages/torch/__init__.py", line 142, in _load_global_deps
    ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
  File "/media/algo/data_1/software/anconda_install/envs/pytorch1.7.1/lib/python3.7/ctypes/__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /media/algo/data_1/software/anconda_install/envs/pytorch1.7.1/lib/python3.7/site-packages/torch/lib/../../../../libcublas.so.11: symbol free_gemm_select version libcublasLt.so.11 not defined in file libcublasLt.so.11 with link time reference

卸载

conda uninstall pytorch==1.7.1

查看安装的库

conda list

用pip 安装torch

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110  -f https://download.pytorch.org/whl/torch_stable.html

测试

(pytorch1.7.1) admin@admin-System-Product-Name:~$ python
Python 3.7.16 (default, Jan 17 2023, 22:20:44) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.version.cuda
'11.0'
>>> torch.backends.cudnn.is_available()
True
>>> torch.backends.cudnn.version() 
8005
>>>
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐