Why do I get an import error for multiprocessing when my code is called from a unittest? (PyCharm Python 3)
Question: In one of my modules I do the following import:

    
    
    from multiprocessing import Pool
    

This module works fine when called normally, but when I use this from a
unittest, I get the following error:

    
    
    Error
    Traceback (most recent call last):
      File "/share/work/peter/software/lib/python3.2/unittest/case.py", line 387, in _executeTestPart
        function()
      File "/home/peter/current/parallelize/src/parallelize/backend/tests.py", line 52, in test_submit_ok_job
        backend = self._get_multi_processing_backend()
      File "/home/peter/current/parallelize/src/parallelize/backend/tests.py", line 46, in _get_multi_processing_backend
        from parallelize.backend.multiprocessing import MultiprocessingBackend
      File "/home/peter/current/parallelize/src/parallelize/backend/multiprocessing.py", line 2, in <module>
        from multiprocessing import Pool,cpu_count
      File "/home/peter/current/parallelize/src/parallelize/backend/multiprocessing.py", line 2, in <module>
        from multiprocessing import Pool,cpu_count
    ImportError: cannot import name Pool
    

Why does this happen? I am using Python 3.2

_EDIT_ I know notices that this is only the case when the unittest is started
from my PyCharm IDE. When run from the commandline (python3 -m unittest ....)
it works. Is this a bug in the IDE?


Answer: It may be because you have the `...src/parallelize/backend/` directory on your
Python path (perhaps it is the working directory), and Python is trying to
import `Pool` from your own `multiprocessing.py` there, not from the standard
library. I don’t know if it’s possible with PyCharm, but try changing the
working directory to something else.

