Python 导入错误:无法导入名称工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37096364/
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
Python ImportError: cannot import name utils
提问by Eric Fossum
I'm having this issue running a script and it looks like it missed some dependencies, but as you can see below. After installing the missing libraries, it doesn't make any sense.
我在运行脚本时遇到了这个问题,看起来它错过了一些依赖项,但如下所示。安装缺少的库后,没有任何意义。
[ericfoss@maverick-fossum-ddns-net packages]$ python -c "import utils"
[ericfoss@maverick-fossum-ddns-net packages]$ python -c "import requests"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 64, in <module>
from . import utils
ImportError: cannot import name utils
[ericfoss@maverick-fossum-ddns-net packages]$
Any idea why utils
can be imported, but requests
can't?
知道为什么utils
可以导入,但requests
不能吗?
采纳答案by Eric Fossum
Well, after pip uninstall requests
and reinstalling, it no longer would work at all. Luckily, dnf install python-requests
fixed the whole thing...
好吧,在pip uninstall requests
重新安装之后,它根本不再起作用。幸运的是,dnf install python-requests
修复了整个事情......
回答by Eino Malinen
Check if Requests requirements are satisfied:
检查请求要求是否满足:
$ pip show requests
...
Requires: certifi, idna, chardet, urllib3
I hit the same error but I was missing idna
. After installing it the issue resolved.
我遇到了同样的错误,但我错过了idna
。安装后问题解决。
回答by Sumanth Vakacharla
We may see the unable to import utilserror in multiple contexts.
I got this error message when I was migrating scripts from python 2 to 3.
I used the inbuilt python migration automated tool to change the file that is causing the import error using the command 2to3 -w filename
This has resolved the error because the import utils is not back supported by python 3 and we have to convert that code to python 3.
我们可能会在多个上下文中看到无法导入 utils错误。当我将脚本从 python 2 迁移到 3 时收到此错误消息。我使用内置的 python 迁移自动化工具使用命令更改导致导入错误的文件2to3 -w filename
这已解决错误,因为不支持导入工具通过 python 3,我们必须将该代码转换为 python 3。
回答by Abhishek Kulkarni
If you have installed required module and still getting same error. Please restart your terminal window. Make sure you save your previous work. I had same error while importing nlpnet -
如果您已经安装了所需的模块,但仍然出现相同的错误。请重新启动您的终端窗口。确保您保存了以前的工作。我在导入 nlpnet 时遇到了同样的错误 -
ImportError: cannot import name utils
导入错误:无法导入名称工具
first install these modules from cmd as- python -m pip install name utils
首先从 cmd as- python -m pip install name utils安装这些模块
then restartpython terminal. This worked for me.
然后重启python终端。这对我有用。
回答by Hafees Kazhunkil
utils package is not installed
未安装 utils 包
You can install package using
您可以使用安装包
sudo pip install utils