[Vscode configures pytorch]

premise

pytorch has been installed through Anaconda Promp, and the test is successful, and vscode has also been installed.
insert image description here

Configure environment variables

insert image description here

insert image description here
Configure environment variables at both paths, the configuration method is as follows insert image description here
and click OK.

Configure json in vscode

Open Vscode, click File>>Preferences>>Settings>>Extensions in the upper left corner, find python in the extension, click on the right to insert image description here
modify the path in the red box below, and modify it to the location of python.exe in pytorch installed in Anaconda , it's normal to open it differently from mine, and make up for what's missing.insert image description here

test

Remember to save the file and restart vscode. Create a py file and run the following code:

import torch
print(torch.cuda.is_available())

run successfully

Guess you like

Origin blog.csdn.net/weixin_45769992/article/details/125862617