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?
Please sign in to leave a comment.
Yes, it there are modules, which names overlap library files, it can break debugger: https://youtrack.jetbrains.com/issue/PY-26903
Hi! Please, provide a stack trace for the ImportError. Could you please provide a sample project for reproducing the issue?
Same issue here.
Hi Andybergon! Could you please provide a code sample for reproducing the problem?
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
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
print(sys.path)
Yes I have those 2 checked.
sys.path
Hi All!
I have the same issue, but i still don't know how to solve it!
I have both "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" options checked.
Here is my RUN sys.path (RUN works fine)
['D:\\Projects\\website-autotests\\API-tests-web\\src\\tests\\ante',
'D:\\Projects\\website-autotests\\API-tests-web',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\config',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\tests',
'D:\\Projects\\website-autotests\\API-tests-web\\src',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\tests\\ante',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\config\\plugins\\python-ce\\helpers\\pycharm',
'D:\\Python\\Python38-32\\python38.zip',
'D:\\Python\\Python38-32\\DLLs',
'D:\\Python\\Python38-32\\lib',
'D:\\Python\\Python38-32',
'D:\\Projects\\website-autotests\\API-tests-web\\venv',
'D:\\Projects\\website-autotests\\API-tests-web\\venv\\lib\\site-packages',
'D:\\Python\\Python38-32\\lib\\site-packages']
Here is DEBUG sys.path (that fails to import test.ante)
['D:\\Projects\\website-autotests\\API-tests-web\\src\\tests\\ante',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\config\\plugins\\python-ce\\helpers\\pydev',
'D:\\Projects\\website-autotests\\API-tests-web',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\config',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\tests',
'D:\\Projects\\website-autotests\\API-tests-web\\src',
'D:\\Projects\\website-autotests\\API-tests-web\\src\\tests\\ante',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\config\\plugins\\python-ce\\helpers\\pycharm',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\config\\plugins\\python-ce\\helpers\\third_party\\thriftpy',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\config\\plugins\\python-ce\\helpers\\pydev',
'C:\\Users\\LLirik\\.IdeaIC2019.2\\system\\cythonExtensions',
'D:\\Python\\Python38-32\\python38.zip',
'D:\\Python\\Python38-32\\DLLs',
'D:\\Python\\Python38-32\\lib',
'D:\\Python\\Python38-32',
'D:\\Projects\\website-autotests\\API-tests-web\\venv',
'D:\\Projects\\website-autotests\\API-tests-web\\venv\\lib\\site-packages',
'D:\\Python\\Python38-32\\lib\\site-packages']
Definately the issue is about paths. But how to configure debug properly?
Hi Gmarkidonov! Do you have a module with name which shadows standard library? Unfortunately, PyCharm debugger fails in this case:
https://youtrack.jetbrains.com/issue/PY-23615
Try to temporary rename this module or file
I can't believe that the most usable module name is the issue.
I changed the name of "tests" to "custom_tests" and it fixed the issue.
I wonder that this way of debugging works like this. Because, you know, crushing because of "testing" is the same as crashing because of "src" if it could doing so.
Nonetheless it works. Thanks.
Hi Kirill Markidonov! Unfortunately, we had another issue with `tests` in Python plugin, which should be fixed in IDEA 2019.2.5: https://youtrack.jetbrains.com/issue/PY-37226