最近学习pytorch,需要安装环境,我的cuda环境如下:
可以看到我的cuda 环境是11.5,然后在pytorch官网:https://pytorch.org/get-started/locally/
看到这里没有11.5,只有11.3,后来没办法直接安装先(需要安装anaconda环境)
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
安装以后出现如下,表示安装成功:
接着试了一下,看看有没有安装成功:
发现没有成功?
后来一想,应该要在anaconda环境下的python才行,然后:
cd /home/caizc/anaconda3/
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
果然成功了。
接着pycharm进行设置:
File->setting
在上面选择刚才anaconda中的python即可,因为在其它地方也安装了pytorch,所以位置非常重要。
测试:
import torch
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
print(torch.__version__)
print('torch cuda:',torch.cuda.is_available())
OK 成功了