0

I see in several old questions that around the switch from Python 2 to Python 3, implicit relative imports were not allowed. However, I ran into a problem that seems to suggest they do happen and am wondering if something changed or if my understanding is incorrect. Edit: To clarify, I thought the below would not be an implicit relative import, but it seems to act like it.

I made an empty file called queue.py and another file called uses_queue.py which contains:

from multiprocessing import Queue
q = Queue()

which crashes on execution saying ImportError: cannot import name 'Empty' from 'queue' however it will not crash if I delete that aforementioned empty file called queue.py. Changing from multiprocessinging to from .multiprocessing or _multiprocessing or ._multiprocessing which didn't change anything.

rfii
  • 487
  • 2
  • 12
  • That's not an implicit relative import. This would have failed the same way since Python 3.0 (and it would have failed the same way in Python 2 as well). – user2357112 Jul 16 '20 at 23:14
  • Thanks could you please clarify a bit? The example I posted is supposed to be an import from sys.path but it seems to be trying to do a relative import, because it crashes when there is a file with the same name as the importation target located in the same folder as uses_queue.py. In other words, I would expect what I wrote to NOT be an implicit relative import but it seems to act like it is. In other words, why is it looking for files in the CWD and why is it crashing? Sorry I am just getting started and trying to learn. Thank you – rfii Jul 16 '20 at 23:17
  • Your current directory is *on* `sys.path`. – user2357112 Jul 16 '20 at 23:27
  • Perhaps I am using the wrong terminology. What is the directory called for where `uses_queue.py` resides? What is the directory called for where all the built in modules like time and multiprocessing reside? I understand you say it will crash and I see that it does, but I am trying to understand why. Thanks for any clarification you can provide. – rfii Jul 16 '20 at 23:36

0 Answers0