我导入的 Python 模块
import Queue
from threading import Thread
import time
但是当我运行代码时
File "b1.py", line 3, in <module>
import Queue
ModuleNotFoundError: No module named 'Queue'
我在 SO 上看到过类似的帖子,但对我来说没什么用
/usr/bin/python3 --version
Python 3.5.2
milenko@milenko-System-Product-Name:~$ python --version
Python 3.6.0 :: Anaconda custom (64-bit)
如果我改成
from multiprocessing import Queue
没有导入问题。但比我有这个
AttributeError: 'Queue' object has no attribute 'join'
接下来我应该尝试什么?
最佳答案
在 Python 2 上,模块名为 Queue
,在 Python 3 上,它是 was renamed关注PEP8 guidelines (模块名称全部小写),使其成为 queue
。 类在所有版本(PEP8 之后)上都保持Queue
。
通常,您编写版本可移植导入的方式是:
try:
import queue # Python 3 import
except ImportError:
import Queue as queue # If queue missing, we're on Py2, import Py2 as Py3 name
关于python - 没有名为 'Queue' 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46363871/