queue ImportError in python 3
Question:
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
Answers:
Replace #!/usr/bin/env python3
with #!/usr/bin/python3
If your env isn’t set up correctly then #!/usr/bin/env python3
may not work. If #!/usr/bin/python3
gives the same error then try running /usr/bin/python3 --version
in your shell as a sanity check.
If you don’t get a sensible output from /usr/bin/python3 --version
then you have odd installation of python 3 and I suggest installing it using your package manager (apt-get
, yum
, homebrew
or whatever you prefer – this will probably fix the !#/usr/bin/env
issue).
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
for ImportError: No module named ‘Queue’ in Python3, just replace the sentence “import Queue” with “import queue as Queue“.
A kinda standard cross py2-py3 compatible version:
try:
import queue
except ImportError:
import Queue as queue
If you are using python3, try
from queue import Queue
queue = Queue()
I am using python 3.6
import queue as Queue
workQueue = Queue.Queue(10)
This method works for me.
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
Replace #!/usr/bin/env python3
with #!/usr/bin/python3
If your env isn’t set up correctly then #!/usr/bin/env python3
may not work. If #!/usr/bin/python3
gives the same error then try running /usr/bin/python3 --version
in your shell as a sanity check.
If you don’t get a sensible output from /usr/bin/python3 --version
then you have odd installation of python 3 and I suggest installing it using your package manager (apt-get
, yum
, homebrew
or whatever you prefer – this will probably fix the !#/usr/bin/env
issue).
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
for ImportError: No module named ‘Queue’ in Python3, just replace the sentence “import Queue” with “import queue as Queue“.
A kinda standard cross py2-py3 compatible version:
try:
import queue
except ImportError:
import Queue as queue
If you are using python3, try
from queue import Queue
queue = Queue()
I am using python 3.6
import queue as Queue
workQueue = Queue.Queue(10)
This method works for me.