ImportError: No module named 'Queue'

PythonPython Requests

Python Problem Overview


I am trying to import requests module, but I got this error my python version is 3.4 running on ubuntu 14.04

>>> import requests
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 10, in <module>
    from queue import LifoQueue, Empty, Full
ImportError: cannot import name 'LifoQueue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/requests/__init__.py", line 58, in <module>
   from . import utils
  File "/usr/local/lib/python3.4/dist-packages/requests/utils.py", line 26, in <module>
    from .compat import parse_http_list as _parse_list_header
  File "/usr/local/lib/python3.4/dist-packages/requests/compat.py", line 7, in <module>
    from .packages import chardet
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/__init__.py", line 3, in <module>
    from . import urllib3
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/__init__.py", line 10, in <module>
    from .connectionpool import (
  File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 12, in <module>
    from Queue import LifoQueue, Empty, Full
ImportError: No module named 'Queue'

Python Solutions


Solution 1 - Python

import queue is lowercase q in Python 3.

Change Q to q and it will be fine.

(See code in https://stackoverflow.com/a/29688081/632951 for smart switching.)

Solution 2 - Python

Queue is in the multiprocessing module so:

from multiprocessing import Queue

Solution 3 - Python

I solve the problem my issue was I had file named queue.py in the same directory

Solution 4 - Python

It's because of the Python version. In Python 2.x it's import Queue as queue; on the contrary in Python 3 it's import queue. If you want it for both environments you may use something below as mentioned here

try:
   import queue
except ImportError:
   import Queue as queue

Solution 5 - Python

In my case it should be:

from multiprocessing import JoinableQueue

Since in python2, Queue has methods like .task_done(), but in python3 multiprocessing.Queue doesn't have this method, and multiprocessing.JoinableQueue does.

Solution 6 - Python

I run into the same problem and learn that queue module defines classes and exceptions, that defines the public methods (Queue Objects).

Ex.

workQueue = queue.Queue(10)

Solution 7 - Python

I just copy the file name Queue.py in the */lib/python2.7/ to queue.py and that solved my problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAli FakiView Question on Stackoverflow
Solution 1 - PythonPacerierView Answer on Stackoverflow
Solution 2 - PythonpeterView Answer on Stackoverflow
Solution 3 - PythonAli FakiView Answer on Stackoverflow
Solution 4 - PythonGPrathapView Answer on Stackoverflow
Solution 5 - PythonPanfeng LiView Answer on Stackoverflow
Solution 6 - PythonasfawhView Answer on Stackoverflow
Solution 7 - PythonxiaojueguanView Answer on Stackoverflow