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'.
Related
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).
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~
I'm developing a cassandra storage finder for graphite-api.
graphite-api is installed via pip and run via gunicorn so I can't just call the script with a debugger but want to use interactive debugging.
When I import pdb in my storage finder and set a breakpoint, the code will halt there, but how can I connect now to the headless running pdb in the script?
Or is my approach to this debugging problem the wrong one and this has to be done in a completely other way?
pdb gives control over to gunicorn, which is not what you want. Have a look at rpdb or other remote debugging solutions.
I'm writing an Python Bottle application (Python 2.7.2 and Bottle 0.10.9) and developing it in the WingIDE (3.2.8-1) Professional for Linux. This all works well, except when I want to debug the Bottle application. I have it running in standalone mode within WingIDE, but it won't stop at any of my break points in the code, even if I set Bottle.debug(False). Does anyone have any suggestions/ideas about how I can setup Bottle so it will stop on breakpoints within WingIDE?
If you have the reloader set to true bottle starts a subproccess for the actual app. In Wing you need to turn off the reloader, then it should work.
run(reloader=False).
But you will have to restart the app in wing every time you make changes.
Are you debugging under WSGI using wingdbstub.py or launching bottle from the IDE? I'm not that familiar with bottle but a common problem is a web framework's reload mechanism running code in a sub-process that is not debugged. I'm not certain bottle would do that under WSGI, however, but printing the process id at time of importing wingdbstub (or startup if launching from the IDE) and again at the line where the breakpoint is missed would rule this in our out. The "reloader" arg for Bottle.__init__ may be relevant here. If set to True, try setting it to False when debugging under Wing.
Another thing to try is to raise an exception on purpose where the breakpoint is (like "assert 0, 'test exception'" and see if this exception is reported in Wing's debugger in the Exceptions tool and if so whether Wing also manages to open the source code. If bottle is running code in a way that doesn't make it possible to find the source code then this would still stop on the assertion (Wing's debugger stops on all assertions by default even if the host code handles the exception) but it would fail to show the debug file and would put up a message in the status area (at bottle of IDE screen and in the Messages tool) that indicates the file name the debug process specified. Depending on this it may be possible to fix the problem (but would require modifying Bottle if the file name is something like "".
BTW, to insert code that is only run under Wing's debugger us something like this:
import os
if 'WINGDB_ACTIVE' in os.environ:
# code here
If this doesn't help please email support at wingware dot com.
I using Eclipse with PyDev to develop Django Webapplication. I can start my webserver with
python manage.py runserver
and then I can test my webapplication locally in my browser. However everytime I change the sourcecode I have to restart eclipse so that these changes get applied in my webapplication.
I guess I have to somehow restart the webserver so that my sourceode gets interpreted again so that my changes get applied. But how do I do that? I couldnt find any command to do so.
Django dev server restarts it self when python code changes. This may not happed if you run it with noreload option
./manage.py runserver --noreload
Another case when the server is not reloaded automatically is when the files changes is not used by django. For example if you have syntax error in your admin.py django won't use it. And changing it won't restart the server.
Have in mind that if you use eclipse debug you will have to run django with noreload because of an bug that does not relaunch the instance but starts a new one.
First, configure the project as a django project in eclipse, if not already so. (Right click on the project, and select PyDev -> Set as Django Project).
Second, click on the green run button at the top, and select "run configurations". Select the PyDev Django icon and hit the new launch configuration button at the top. Enter the project name, (let's say testproject), and "${workspace_loc:testproject}/${DJANGO_MANAGE_LOCATION}" for the main module.
On the Arugments tab, enter "runserver 0.0.0.0:8000 --noreload" if you want to your server to be visible for machines outside yours, or "runserver --noreload" if you want access on your machine only, and change the working directory to "${workspace_loc:}".
Click apply and you should be set to go!
Here's what it should look like when running inside of eclipse: