The following simple script raises an ImportError in python3:
from multiprocessing import Queue
queue = Queue()
print("OK")
The key to reproduce this error is to name this file queue.py
, and then the following messages appear:
Traceback (most recent call last):
File "queue.py", line 3, in <module>
queue = Queue()
File "/home/wangc/app/anaconda/lib/python3.5/multiprocessing/context.py", line 100, in Queue
from .queues import Queue
File "/home/wangc/app/anaconda/lib/python3.5/multiprocessing/queues.py", line 20, in <module>
from queue import Empty, Full
File "/home/wangc/temp/queue.py", line 3, in <module>
queue = Queue()
File "/home/wangc/app/anaconda/lib/python3.5/multiprocessing/context.py", line 100, in Queue
from .queues import Queue
ImportError: cannot import name 'Queue'
If the file is named as queueue.py
, then everything is fine.
I think this is because multiprocessing module is trying to import Queue from my queue.py since its name coincides with some file in multiprocessing module.
However, If it is how python works, then I should avoid filenames of any possible internal libraries, which is not practical.
Is this error attributed to the same filename of my file and some file in multiprocessing module? And if it is, how can I ensure my filenames are distinct from files of any possible library in general programming?