Skip to content Skip to sidebar Skip to footer

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. [

Solution 1:

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.


Solution 2:

Well, after pip uninstall requests and reinstalling, it no longer would work at all. Luckily, dnf install python-requests fixed the whole thing...


Solution 3:

We may see the unable to import utils error 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.


Solution 4:

I ran into a similar problem when running Jupyter Lab:

$ jupyter-lab --ip 0.0.0.0
Traceback (most recent call last):
  File "/Users/gtholpadi/opt/anaconda3/bin/jupyter-lab", line 6, in <module>
    from jupyterlab.labapp import main
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab/labapp.py", line 14, in <module>
    from jupyterlab_server import slugify, WORKSPACE_EXTENSION
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/__init__.py", line 4, in <module>
    from .app import LabServerApp
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/app.py", line 10, in <module>
    from .handlers import add_handlers, LabConfig
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/handlers.py", line 18, in <module>
    from .listings_handler import ListingsHandler, fetch_listings
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/listings_handler.py", line 17, in <module>
    import requests
  File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/requests/__init__.py", line 120, in <module>
    from . import utils
ImportError: cannot import name 'utils' from partially initialized module 'requests' (most likely due to a circular import) (/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/requests/__init__.py)

requests was already installed when I got this error. I tried pip install -U requests and that solved the problem.


Solution 5:

utils package is not installed

You can install package using

sudo pip install utils

Post a Comment for "Python ImportError: Cannot Import Name Utils"