Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'Queue'

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'
like image 959
Ali Faki Avatar asked Oct 30 '15 09:10

Ali Faki


People also ask

How do I install a queue?

Click the "Install Queue Service" button from the menu bar. Open Services, right click on RE Queue Service or FE Queue Service, select Properties. Click the "Log On" tab and mark the radio button labeled "This account" Click the "Browse" button, enter the name of the domain "Queue Windows account".

How do I import a python queue?

So you must not write name of the module, just q = Queue(maxsize=100) . But if you want use classes with name of module: q = queue. Queue(maxsize=100) you mast write another import string: import queue , this is mean that you import all module with all functions not only all functions that in first case.

How do I find the size of a python queue?

To get the length of a queue in Python:Use the len() function to get the length of a deque object. Use the qsize() method to get the length of a queue object.


6 Answers

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

like image 103
Pacerier Avatar answered Oct 06 '22 04:10

Pacerier


Queue is in the multiprocessing module so:

from multiprocessing import Queue
like image 37
peter Avatar answered Oct 06 '22 05:10

peter


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

like image 23
Ali Faki Avatar answered Oct 06 '22 05:10

Ali Faki


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
like image 25
GPrathap Avatar answered Oct 06 '22 05:10

GPrathap


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.

like image 20
Panfeng Li Avatar answered Oct 06 '22 04:10

Panfeng Li


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)
like image 34
asfawh Avatar answered Oct 06 '22 04:10

asfawh