当前位置:网站首页>Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').

Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').

2022-06-25 05:03:00 MondayCat111

Installed at that time torch Try using the official website conda Method , A network error will be reported during each download , So through pip install , Install the installation package , adopt pip install torch-1.3.0+cu92-cp37-cp37m-win_amd64.whl and pip install torchvision install ( perhaps pip install torchvision-0.4.1+cu92-cp37-cp37m-win_amd64.whl).
Attach download address torch and torchvision

After installation , Can be in python neutralization pycharm Use in pytorch, But in jupyter notebook But you can't use . Use times wrong ,ModuleNotFoundError:No module named ‘torch’
 Insert picture description here
 Insert picture description here
Discover by looking , adopt pip Installed torch be not in conda Environment , By entering conda list Check the installed packages and see if they are torch( adopt pip The installed package should be installed in the local environment , and conda Is one of my own python Environmental Science , So there's no ), Need to be in conda One more time , In my case , This method works . Insert picture description here
The method is as follows :
① Install the package locally , Website see above . Need to put in c/user/… Next , If it's not in the right place , The command line will give an error warning , Just change your position .
 Insert picture description here
② Create a virtual environment such as pytorch, Then switch to the virtual environment , There are corresponding tutorials on the Internet . adopt pip install , stay anaconda prompt in , Input pip install torch-1.3.0+cu92-cp37-cp37m-win_amd64.whl and pip install torchvision install ( perhaps pip install torchvision-0.4.1+cu92-cp37-cp37m-win_amd64.whl)
 Insert picture description here
③ After installation , Can be used in this virtual environment torch 了 , Then add the virtual environment to jupyter notebook It's OK in China . Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[MondayCat111]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210528019839.html