Pycharm CE not hitting breakpoints in my Django project - python

I have my project properly configured to run manage.py in the right place, with the right settings.
I also have debug breakpoints set in a method that I know with certainty is being executed (I've put a print statement there and it executed as expected). The breakpoints are not disabled or conditional:
When I hit the "Run in debug mode" button, using the above run configuration (I'm sure it's the same one because it's the only one I've configured for this project), this is the console output I get:
pydev debugger: process 38083 is connecting
Connected to pydev debugger (build 192.5728.105)
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 23, 2020 - 19:22:22
Django version 3.1.4, using settings 'FEArena.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
When I tried putting a breakpoint in manage.py, it worked as expected, triggering just when I hit the 'debug' button. However, after the app has started, when I use a REST client to trigger the above method, the one with breakpoints in it, the breakpoints do not trigger and the debugger doesn't start. I get a 200 OK response in my REST client, but PyCharm does not stop and execute the debugger at any point.
I looked at other answers that advised setting "Gevent compatible debugging" (which I don't have, because I'm using Community Edition), and I've tried deleting the .idea/ folder for the project, which also didn't fix the issue. I'm not sure what else could be causing this. I just want to debug my program.
My PyCharm version information is
PyCharm 2019.2 (Community Edition)
Build #PC-192.5728.105, built on July 23, 2019
Runtime version: 11.0.3+12-b304.10 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.7
GC: ParNew, ConcurrentMarkSweep
Memory: 4029M
Cores: 8
Registry:
Non-Bundled Plugins: com.karateca.jstoolbox, mobi.hsz.idea.latex, net.seesharpsoft.intellij.plugins.csv, nl.rubensten.texifyidea, org.intellij.plugins.markdown
What could be causing the breakpoints to not be triggered, and how do I fix this? I need breakpoints to debug other parts of my program.

Are you running your server in a console by any chance? If thats the case try stopping the server runing in console and restart the one in PyCharm

I was having a similar issue previously in PyCharm when I was invoking executor.submit. I had to insert a line requesting the results of the code in order to re-invoke the expected debugging behaviour. If your code is threaded, you may wish to start there.
future = executor.submit(control, channel) # spawn a function control(channel)
print(f'Future result is: {future.result()}') # new line I had to add to enable debugging
Edit: Adding the link to the thread that helped me with similar behaviour in PyCharm. concurrent.futures.ThreadPoolExecutor doesn't print errors

My current working configuration is on this :
It does not have any script path or parameters.
When I click on the "Debug" green button, the command automatically launched is :
/Users/.../virtualenv/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 55583 --file /Users/.../manage.py runserver 8000
What about yours ?

Hi I am writing this answer as I cannot comment because of my reputation no. By any chance, did you installed cython debugger toolkit that pycharm keeps on suggesting? If so, i have faced the same issue. The solution is to delete cython speedups somehow. You can follow this link to do that.
Basically you have to go to the directory called _pydevd_bundle and delete pydev*.so files. Now that requires root privilege. If you have that and you are able to delete them, then most likely it will work(provided you had installed cython debugger extension).

Related

Remote debugging eclipse+pydev with ssh connection to linux server breakpoints are not found

I am struggling on setting up pydev remote debugging feature.
I run Eclipse on my windows laptop and the code is on the linux server.
As far as I've understood the manual http://www.pydev.org/manual_adv_remote_debugger.html I have to have an exact local copy of the code to debug on my laptop and I need to link it with the code on the linux server with PATHS_FROM_ECLIPSE_TO_PYTHON variable. However no matter how I set this variable in the pydevd_file_utils.py on the server the paths in the error message don't change.
For each breakpoint I receive:
pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/user/D:\Workspace\RemoteSystemsTempFiles\****\home\user\Code\reco\Test2D.py (will have no effect)
Error message
How can I link this particular file, so I can debug it with breakpoints? Is a local copy of the file necessary, even though I can access the original file via windows network drive mapping?
Actually,
I have solved it in a not very intuitive way. For some reason, PATHS_FROM_ECLIPSE_TO_PYTHON variable in the pydevd_file_utils.py file didn't change the really used path for the server. I had to manually edit the _norm_file_to_server function in changing the path for the translated variable from _NormFile(translated) to the path of the debugged file e.g "home/user/code.py". After starting debug server I could start the execution of the file with a remote console, e.g python "home/user/code.py"and it worked properly by popping up and stopping at the breakpoint in eclipse.

PyCharm docker debugging error

SEE EDITS
I'm trying to get the latest version of PyCharm to successfully debug Django running inside Docker. However I'm having trouble setting up the remote python interpreter and I get an error as soon as I try to start the debugger.
Can't run remote python interpreter: com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"the working directory 'C:/Program Files (x86)/JetBrains/PyCharm 171.2613.10/jre64/jre/bin' is invalid, it needs to be an absolute path"}
The path, in my eyes looks pretty absolute, so I'm guessing its something else. I'm not even sure who or what is causing the error. The docker container (because of the JSON response) or PyCharm.
Running
PyCharm 2017.1
Docker for Windows (docker version 1.13.0)
Any thought of what I might be missing/having problem with?
Edit
Forgot to include my settings from PyCharm on how I set up the remote interpreter.
I get no errors with the above settings
Edit 2
It looked like the "Django project root" had accidentally been set to the incorrect path above. So that is fixed. My problem now is that when I run the Run/Debug Configuration it tries to start the server again, which is already running inside the docker container. Is there no way to attach to the already running python process?
Edit 3
I've now managed to get a "success" message when starting the debugger (PyCharms Python Remote Debugger) and starting the server after. However I seems like the debugger stops listening after 1 second (or less). My theory is that the debugger looses connection after it has passed the pydevd.settrace() function call. I have placed the following code (of the top of my head) at the bottom of manage.py:
sys.path.append('pycharm-debug.egg')
import pydevd
pydevd.settrace('192.168.1.100', port=21000)
What am I missing?
EDIT 4
After investigating further I now seem to successfully connect the debugger on server startup. However, if the pydevd.settrace(....) function call is present the server never actually starts. The startup seems to freeze/stop on python manage.py runserver 0.0.0.0:8000. As soon as I remove the settrace line. The server starts without issue. Any ideas?
I also get this message when the server is starting:
warning: Debugger speedups using cython not found. Run '"/usr/local/bin/python" "/usr/local/lib/python3.5/site-packages/setup_cython.py" build_ext --inplace' to build.
The problem is that I can't run the command listed in the message because the file setup_cython doesn't exist.
You're right! It really don't start the runserver process, but I believe it's not because isn't working, but because it is.
See, when you successfully connected the pydevd settrace with the debugger server you had to configure on PyCharm it already worked, at least it worked for me.
I believe the reason runserver isn't working is because the warning created by the missing cython is stopping the debugger, the only thing you have to do is tell it to keep running and jump that warning clicking on the green right-pointing arrow to do so.
PS.
I'm debugging a django application running on docker (docker-machine), the host IP, in that case is 192.168.99.1
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "helpdesk.settings")
from django.core.management import execute_from_command_line
sys.path.append('pycharm-debug.egg')
import pydevd
pydevd.settrace('192.168.99.1', port=3000, stdoutToServer=True, stderrToServer=True)
execute_from_command_line(sys.argv)
Hope I helped!
I have the same quesiton
I had solved it by editing the pycharm Interpreter
you can add some config to the "Path mappings" as follows
before the "=" , write your local code path
after the "=" , wirte your cloud server code path
Interpreter-config.png
I only change this, it works!!!
Hope that can help you~

How to debug remote python script?

I am looking for a way to debug remote python script without any set up like in the answer here
I set remote interpreter, set up a debug configuration, click a debug button and got error Event not found:
ssh://myuser#my_ip:my_port/usr/local/bin/python -u /myuser/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support --client '0.0.0.0' --port 46994 --file /opt/my_work_dir/my_script.py
/: Event not found.
Seems like pyCharm takes care about all debug setting --multiproc --qt-support --client '0.0.0.0' --port 46994 but I have the wrong configuration.
Is there a way how to debug python script without putting pydevd.settrace('host', port=21000, stdoutToServer=True, stderrToServer=True) and other actions?
I was able to fix this problem by reinstalling PyCharm.
(# 1 and 5 are optional)
Export minimum settings you want to restore such as Keymap (File > Export Settings)
Uninstall your current PyCharm
Install new PyCharm
Launch new PyCharm and don't import your pre-existing setting at the first start up
Import your settings from the old PyCharm (File > Import Settings)
I guess this happens when some environment related settings are messed up.
Notice that you need to remember your settings for the remote interpreter as it will be gone when reinstalling.
I use vagrant quite often with pycharm and debugging has always worked great for me as long as i setup the interpreter to the one inside the vagrant box running.
If you go to settings->project->project interpreter and then setup a connection to your remote interpreter it will usually install the pycharm-debug.egg etc and you can debug run your project against this interpreter and set breakpoints in pycharm and it will break on those.
Here is their docs on setting this up https://www.jetbrains.com/help/pycharm/2016.1/configuring-remote-python-interpreters.html
I set up remote debugging as described under the section
Remote debug with a remote interpreter
(not the Server!!) and it works very well.
Here the link: https://www.jetbrains.com/help/pycharm/2016.1/remote-debugging.html
You just have to set up the remote interpreter (I used ssh) and then set up your run configurations. Let me know if you need further help.
Here is my run configuration in PyCharm:
It might be the same issue as this. Use bash as your login shell if you use another one like csh or tcsh.

Connecting to remote interpreter when starting PyCharm

I have a remote interpreter set up in PyCharm.
Everytime I close and reopen PyCharm, the connection seems to be broken, and the process to "reopen" the connection doesn't feel efficient to me.
Before doing the following, it is not possible to run any script.
Here is what I usually do:
File -­> Settings
Project -> Project Interpreter
Click on the gear icon on the right.
Choose "More"
With my remote interpreter selected, click on "Edit"
Change "SSH Credentials" for "Deployment Configuration" (all the info is already filled)
Click "ok" multiple times to close everything up.
At that point, I can run any scripts on the remote machine.
What is the best/fastest way to do this? (any way to "save the settings"?)
Check option "Visible only for this project" of deployment configuration. This error occurs when the check mark is set.
https://www.jetbrains.com/help/pycharm/2018.3/deployment-connection-tab.html
if this checkbox is selected in an SFTP configuration, you cannot use
its SSH credentials for configuring a remote interpreter.
This was a bug in version 4.0.2 of PyCharm and was corrected in version 4.0.3.
Edit: No longer true. I tried with another computer and having the most recent version doesn't fix the problem.
i meet the same error, file->settings checking your interpreter setting,
You don't set the 'host' and 'post',or your set but the content was clear. check again, and it truly work

Django - Could not find source to reload

I'm currently using LiClipe with PyDev to debug my project.
I have a separate module which sits in the core directory of my Django project.
While the project is running in Debug mode I'm able to edit code, save it and then get a confirmation that it is working in the console.
However when I edit this particular module I get the following issue which I'm not sure how to approach:
pydev debugger: Start reloading module: "pspotter" ...
pydev debugger: Could not find source to reload (mod: pspotter)
pydev debugger: reload finished
Furthermore the code doesn't seem to be running as it's using apscheduler.
Am I meant to reference this file from somewhere else?
In the latest version, when you're running under the debugger, PyDev will try to make a reload on the existing process. In this particular case it can't find the module to reload in sys.modules and it's just warning you that the reload failed (so, it's just signalling that you have to restart the debug session in order to get those changes as it wasn't able to do a 'hot' reload).
If you don't want to use that feature, you can disable it in the preferences > pydev > debug > 'when file is changed automatically reload'.

Categories