简体   繁体   中英

Why does importing Pytorch in Sublime Text cause a ModuleNotFoundError?

The command 'import torch' causes the build error: 'ModuleNotFoundError: No module named 'torch''.

But when I run the command in the terminal, pytorch works just fine (Python 3.7.X).

Are you using a venv in the project you are right now? If that is so, then you need to install torch in that venv , as it has been created just for the project, so it has not got any extra modules like that one.

Take a look at this . And make sure that the module is in the environment your project is!

In Pycharm for example, whenever you create a new project with a new venv (virtual environment), you need to add to your project settings->interpreter settings the module manually, so it can be imported. Because it may be installed in your system, but not in that venv specifically, which will look in there!

try this link it might help. Also Faced similar issue in Windows 10 with Anaconda installed. Installed pytorch package using conda install command which I found here: http://pytorch.org/

The usual import from command-line worked for my environment(torch):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM