赞
踩
打开pycharm,new project
new environment using conda
修改环境名 项目名,python版本选择3.9(我的电脑pyTorch在3.9上跑通了,其他版本暂时没试)
create
打开终端,进入刚创建的conda环境
在该环境安装pyTorch,即在终端输入
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
在pyCharm验证是否成功
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.cuda.is_available())
print(torch.__version__)
输出结果如下:
成功!
new project ,使用默认环境
File-settings ,打开设置
点击python Interpreter
点击右上角 add Interpreter
选择add local interpreter,点击conda environment,选择 using existing environment,选择已配置好的环境,点击ok
点击右下角apply
点击ok
在pyCharm验证是否成功
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.cuda.is_available())
print(torch.__version__)
输出结果如下:
成功!
new project
点击 previously configured interpreter
选择已有环境
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。