PyCharm - some breakpoints not working in a Django

2019-04-07 08:50发布

问题:

I'm seeing some bizarre behaviour in PyCharm. I have a Django project where breakpoints stopped working in some files but not others. For example, all the breakpoints in my app's views.py work fine, but all the breakpoints in that same app's models.py are just ignored.

I've tried the following but no joy:

  • double-check the breakpoints are enabled
  • removing/re-adding the breakpoints
  • closed/re-opened the project
  • quit & re-launch PyCharm
  • delete my configuration and create a new one

Some details:

  • PyCharm 2.7.3
  • Python 2.7.2 (within virtualenv)
  • Django 1.5.1

I'm not using any special settings in my configuration. Any ideas?

回答1:

If you have the setting "Gevent compatible debugging" enabled it does not seem to hit breakpoints in a non-Gevent django application.

Find it under Preferences -> Python Debugger -> Gevent compatible debugging



回答2:

While I don't know why or how, the problem was resolved by deleting the ".idea" directory within the Django project directory. This is where the PyCharm project data lives, so by removing this directory you will lose your project specific settings, so just be aware. Hope this helps someone else.



回答3:

Make sure that the breakpoint is not located in a project (dependency) directly symlinked from the project (the main project) that uses the symlinked project. I say directly, because PyCharm does follow breakpoints in symlinked projects located in site-packages, but this is an indirectly simlinked project.

Ex:

Scenario 1

Project A

  • ProjB_SymLink

Site-Packages

  • Other Packages

Scenario 2

Project A

Site-Packages

  • ProjB_SymLink
  • Other Packages

In Scenario 1, PyCharm will not see breakpoints located in code under Project B. In Scenario 2, it will.

The below also should be useful: http://devnet.jetbrains.com/thread/442551