9

When I try to import multiprocessing in Python 2.7.5 on OS X 10.6.8, I get this error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 40, in <module>
from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags

I also tried to install python2.7.6 with homebrew, but this error still occurs.

tshepang
  • 12,111
  • 21
  • 91
  • 136
LH2
  • 131
  • 2
  • 3

1 Answers1

2

It sounds like a circular import issue. Try adding this to the the rest of your imports:

from subprocess import _args_from_interpreter_flags

There is a comment above the function in subprocess.py:

# XXX This function is only used by multiprocessing and the test suite,
# but it's here so that it can be imported when Python is compiled without
# threads.

May be related.

Community
  • 1
  • 1
anon582847382
  • 19,907
  • 5
  • 54
  • 57
  • 6
    Thanks. It turned out that in the code that I am maintaining there's a module "subprocess.py" which causes importing multiprocessing to fail as multiprocessing imports the subprocess module(in the standard python library). Moral of the story: 1. don't name your module after a standard python library. 2. Be extra careful when handling ancient codes. (In my case, the python program I was extending was written in the python 2.3 era. So I guess the author, not knowing there would be a "subprocess" module in "future" release of python, named this module "subprocess.py" by coincidence.) – LH2 Mar 07 '14 at 04:51
  • What do you mean by "to the *rest* of your imports"? By saying to add that to the "rest" of your imports - where does that import statement actually go? – Praxiteles Jun 02 '16 at 19:46
  • @Praxiteles typically import statements go at the very top, I was assuming the OP had used some. – anon582847382 Jun 04 '16 at 23:01