Python ModuleNotFoundError:没有名为“tools.nnwrap”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56859803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:38:37  来源:igfitidea点击:

ModuleNotFoundError: No module named 'tools.nnwrap'

pythonpycharm

提问by Singh

I am trying to import a package "torch". For same, I tried to install it using pip command as below, installation even started but after few seconds it got error

我正在尝试导入一个包“火炬”。同样,我尝试使用如下的 pip 命令安装它,安装甚至开始了,但几秒钟后出现错误

below is the command that I executed

下面是我执行的命令

pip install torch

pip install torch

Error that I got:

我得到的错误:

from tools.nnwrap import generate_wrappers as generate_nn_wrappers
    ModuleNotFoundError: No module named 'tools.nnwrap'

OS:Windows. IDE: pyCharm

操作系统:Windows。 IDE: pyCharm

I got the only link related to this issue but I was not able to interpret it.

我得到了与此问题相关的唯一链接,但我无法解释它。

https://www.gitmemory.com/torch

https://www.gitmemory.com/torch

回答by Singh

Anyone who is looking for the solution refer below:

任何正在寻找解决方案的人请参阅以下内容:

It seems command to install torch not is working as expected, instead, you can try to install PyTorch using below command.

似乎安装 Torch 的命令没有按预期工作,相反,您可以尝试使用以下命令安装 PyTorch。

It's working and solved my above-mentioned issue.

它正在工作并解决了我的上述问题。

Run below command(for below-specified OS, package-manager, Language):

运行以下命令(对于以下指定的操作系统、包管理器、语言):

# for OS: Windows, package-manager: pip, Language: python3.6 (below command is valid for only mentioned python 3.6)

pip3 install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp36-cp36m-win_amd64.whl
pip3 install https://download.pytorch.org/whl/cu90/torchvision-0.3.0-cp36-cp36m-win_amd64.whl

For another version/type of the software (OS, package, Language) installed, the command must be generated from the below-mentioned link.

对于安装的其他版本/类型的软件(操作系统、软件包、语言),必须从下面提到的链接生成命令。

https://pytorch.org/get-started/locally/

https://pytorch.org/get-started/locally/

回答by Slim

Follow the instructions on https://pytorch.org/get-started/locally/

按照https://pytorch.org/get-started/locally/上的说明进行操作

Choose Package "Pip" if you want to pip install

如果需要,请选择包“Pip” pip install

It will give you output such as

它会给你输出,如

pip3 install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp37-cp37m-win_amd64.whl
pip3 install https://download.pytorch.org/whl/cu90/torchvision-0.3.0-cp37-cp37m-win_amd64.whl

Edit: new install instructions from pytorch.org shows commands such as

编辑:来自 pytorch.org 的新安装说明显示了诸如

pip3 install torch===1.3.1 torchvision===0.4.2 -f https://download.pytorch.org/whl/torch_stable.html

回答by Inna Klimbovskaia

For what it's worth, on Windows 10 in Anaconda, the only command which worked for me was:

值得一提的是,在 Anaconda 的 Windows 10 上,唯一对我有用的命令是:

pip3 install https://download.pytorch.org/whl/cu90/torch-1.0.1-cp37-cp37m-win_amd64.whl

回答by Demotte

To install stable version of pytorch in windows 10 for pycharm, following command should work.

要在 Windows 10 中为 pycharm 安装稳定版本的 pytorch,请使用以下命令。

pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

回答by healer101

This worked for Windows 10 using Python-3.x pip

这适用于使用 Python-3.x 的 Windows 10 pip

pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

回答by James Owers

For me this was fixed by checking my python version - I got this error with python 3.8, but the error went away when I downgraded to 3.7 (install instructions on the siteonly appear to go up to 3.7).

对我来说,这是通过检查我的 python 版本来解决的 - 我在 python 3.8 中遇到了这个错误,但是当我降级到 3.7 时错误消失了(站点安装说明似乎只上升到 3.7)。

回答by Chris

I was getting the same error, then I found that the latest pytorch install requires CUDA 10.1, and once I installed that and the matching cuDNN, then this command line succeeded:

我遇到了同样的错误,然后我发现最新的 pytorch 安装需要 CUDA 10.1,一旦我安装了它和匹配的 cuDNN,这个命令行就成功了:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

回答by Hymanssn

How I fix it in Windows 10 (x64)

我如何在 Windows 10 (x64) 中修复它

31 March 2020

2020 年 3 月 31 日

  1. Install CUDA from here: https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal

    • Version: cuda_10.2.89_441.22_win10.exe
  2. Use official website pytorch: https://pytorch.org/get-started/locally/

    • This command in CMD: pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
  3. In Anaconda3 I tried to use same website just change Package to conda:

    • Command in jupyter notebook: conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
    • enter image description here
    • And after restart it does NOT work
    • So I tried to use pipagain in jupyter notebook: pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
    • enter image description here
    • And it WORKS(if no, you can try to restart kernel):
    • enter image description here
  1. 从这里安装 CUDA: https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal

    • 版本: cuda_10.2.89_441.22_win10.exe
  2. 使用官网pytorch: https://pytorch.org/get-started/locally/

    • CMD中的这个命令: pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
  3. 在 Anaconda3 中,我尝试使用相同的网站,只需将 Package 更改为conda

    • jupyter 笔记本中的命令: conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
    • 在此处输入图片说明
    • 重新启动后它不起作用
    • 所以我尝试pip在 jupyter notebook 中再次使用:pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
    • 在此处输入图片说明
    • 它的工作原理(如果没有,你可以尝试重新启动内核):
    • 在此处输入图片说明

回答by Lawrence Patrick

Had to fix this at two locations:

必须在两个位置修复此问题:

DEV windows 10 machine: CD to C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts execute: conda install pytorch

DEV windows 10 机器:CD 到 C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts 执行:conda install pytorch

DEV Windows MSSQL Server Database Python Services CD to C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\Scripts execute: pip3 install torch

DEV Windows MSSQL Server Database Python Services CD 到 C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\Scripts 执行:pip3 install torch

回答by zzfima

i got rid of this in next way: uninstall Python 32 bit and install 64bit.

我以另一种方式摆脱了这个:卸载 Python 32 位并安装 64 位。

Hereyou can find all versions

在这里你可以找到所有版本

And hereyou can see pip/conda etc cmd commands to run to install torch

在这里,你可以看到PIP /畅达等CMD命令来运行安装火炬