ImportError: Idea CE with python when debugging import module has issue "ImportError"


Idea CE at debugging, has issue "importError : No module named compat", the code following:

from tests.compat import unittest

class TestImportHello(unittest.TestCase):
def test_hello(self):
print 'hello'

if __name__ == '__main__':

bug when i runing(not debugging), hasn't issue.

what setting I would do it?



Hi! Please, provide a stack trace for the ImportError. Could you please provide a sample project for reproducing the issue?


Hi Andybergon! Could you please provide a code sample for reproducing the problem?



I wasn't able to replicate the bug in a test project but I can provide the stack trace!
As OP said the bug happens only during the Debug but it doesn't happen during a normal Run.

This happens only for custom modules, all the system and 3rd party modules are imported fine. I can cmd+click in those modules so probably IntelliJ can find those correctly.


Stack trace:

/Users/abergonzo/anaconda/envs/py27/bin/python "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/" --multiproc --qt-support=auto --client --port 51316 --file /Users/abergonzo/src/
pydev debugger: process 9428 is connecting

Connected to pydev debugger (build 181.4096.5)
Traceback (most recent call last):
File "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/", line 1668, in <module>
File "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/", line 1662, in main
globals =['file'], None, None, is_module)
File "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/", line 1072, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/abergonzo/src/", line 16, in <module>
import as foo
ImportError: No module named foo

Process finished with exit code 1


I debugged that a little bit and probably found what is making the debugger fail! 

A Python package named `code`!

Just try to create a project with 2 Python files, one of them inside a module called code and try to Run and Debug! Probably this module name is used internally and it tries to import the wrong thing.


Hi! Do you have options "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" checked? Could you please add the following lines before the import statement and execute your program under debugger again? 
import sys


Yes I have those 2 checked.




'/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev',
'/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev',

Yes, it there are modules, which names overlap library files, it can break debugger:


Please sign in to leave a comment.