Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

queue ImportError in python 3

I am not sure why I am getting this ImportError. queue.Queue() is in the documentation.

https://docs.python.org/3/library/queue.html?highlight=queue#queue.Queue

I am using it in a function like so:

node_queue = queue.Queue()

error:

Traceback (most recent call last):
  File "./test_jabba.py", line 15, in <module>
    from utils import gopher, jsonstream, datagen, event_gen, tree_diff, postal
  File "/Users/bli1/Development/QE/TrinityTestFramework/poc/utils/tree_diff.py", line 5, in <module>
    import queue
ImportError: No module named queue

Line 5 is import queue:

#!/usr/bin/env python3
import sys                      # access to basic things like sys.argv
import os                       # access pathname utilities
import argparse                 # for command-line options parsing
import queue
like image 526
Liondancer Avatar asked Apr 16 '15 23:04

Liondancer


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

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.

What is LIFO queue in Python?

For a LIFO (Last in First out Queue), the element that is entered last will be the first to come out. An item in a queue is added using the put(item) method. To remove an item, get() method is used.


3 Answers

Another way to avoid version problems is:

import sys
is_py2 = sys.version[0] == '2'
if is_py2:
    import Queue as queue
else:
    import queue as queue
like image 169
m9_psy Avatar answered Oct 08 '22 14:10

m9_psy


A kinda standard cross py2-py3 compatible version:

try: 
    import queue
except ImportError:
    import Queue as queue
like image 30
sorin Avatar answered Oct 08 '22 14:10

sorin


for ImportError: No module named 'Queue' in Python3, just replace the sentence "import Queue" with "import queue as Queue".

like image 5
Dhawaleswar Avatar answered Oct 08 '22 12:10

Dhawaleswar