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

Answered

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__':
unittest.main()

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

what setting I would do it?

 

9 comments

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

0

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

0

Hey!

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/pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 51316 --file /Users/abergonzo/src/bar.py
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/pydevd.py", line 1668, in <module>
main()
File "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/pydevd.py", line 1662, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev/pydevd.py", line 1072, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/abergonzo/src/bar.py", line 16, in <module>
import code.foo as foo
ImportError: No module named foo

Process finished with exit code 1

0

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.

0

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
print(sys.path)

0

Yes I have those 2 checked.

 

sys.path

 

[
'/Users/abergonzo/src/project1/foo',
'/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev',
'/Users/abergonzo/src/project1',
'/Users/abergonzo/src/project1/bar',
'/Users/abergonzo/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.22/log4j-over-slf4j-1.7.22.jar',
'/Users/abergonzo/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.22/jcl-over-slf4j-1.7.22.jar',
'/Users/abergonzo/.m2/repository/org/slf4j/jul-to-slf4j/1.7.22/jul-to-slf4j-1.7.22.jar',
'/Users/abergonzo/.m2/repository/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.jar',
'/Users/abergonzo/.m2/repository/ch/qos/logback/logback-core/1.1.10/logback-core-1.1.10.jar',
'/Users/abergonzo/.m2/repository/ch/qos/logback/logback-classic/1.1.10/logback-classic-1.1.10.jar',
'/Users/abergonzo/Library/Application Support/IdeaIC2018.1/python-ce/helpers/pydev',
'/Users/abergonzo/Library/Caches/IdeaIC2018.1/cythonExtensions',
'/Users/abergonzo/anaconda/envs/py27/lib/python27.zip',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/plat-darwin',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/plat-mac',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/lib-tk',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/lib-old',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/lib-dynload',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/site-packages',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg',
'/Users/abergonzo/anaconda/envs/py27/lib/python2.7/site-packages/IPython/extensions'
]
0

Yes, it there are modules, which names overlap library files, it can break debugger: https://youtrack.jetbrains.com/issue/PY-26903

1

Please sign in to leave a comment.