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
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".
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.
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.
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.
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
A kinda standard cross py2-py3 compatible version:
try:
import queue
except ImportError:
import Queue as queue
for ImportError: No module named 'Queue' in Python3, just replace the sentence "import Queue" with "import queue as Queue".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With