Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ImportError: cannot import name utils

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?

like image 341
Eric Fossum Avatar asked May 08 '16 04:05

Eric Fossum


People also ask

Can not import name Python?

This error generally occurs when a class cannot be imported due to one of the following reasons: The imported class is in a circular dependency. The imported class is unavailable or was not created. The imported class name is misspelled.

How do you fix an import error in Python?

Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH .

What is import error in Python?

In Python, ImportError occurs when the Python program tries to import module which does not exist in the private table. This exception can be avoided using exception handling using try and except blocks. We also saw examples of how the ImportError occurs and how it is handled.


1 Answers

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.

like image 160
Eino Malinen Avatar answered Oct 21 '22 12:10

Eino Malinen