Is it possible?
By debug I mean setting breakpoints, inspect values and advance step by step.
You can do remote debugging of python web apps over TCP/IP with winpdb.
(Link appears down as of June 2019. Try PyPI winpdb)
I haven't used web2py, but if it runs in a terminal window, you can use standard pdb stuff. Add this line somewhere in your code:
import pdb; pdb.set_trace()
This will invoke the debugger and break. Then you can use PDB commands: n to step to the next line, l to list code, s to step into a function, p to print values, etc.
One can debug applications built on Web2py using the following set-up:
Eclipse IDE
Install Pydev into Eclipse
Set Breakpoints on your code as needed
Within Eclipse right-click the file web2py.py and select Debug As -> Python Run
When a breakpoint is hit Eclipse will jump to the breakpoint where you can inspect variables and step thru the code
You can also use Visual Studio 2010. Here's how:
Download and install Python Tools for Visual Studio.
Create a new project from existing code (File > New > Project From Existing Code...)
Specify your web2py folder and use the defaults.
Right-click on web2py.py and choose Set as Startup File.
Set breakpoints and hit F5 (run) or right-click on web2py.py and choose Start with Debugging.
This is a nice setup if you already use visual studio.
Yes, it is possible, Due to the "span prevention" I am still not allowed to post screenshots, but here is a full screenshot hosted at my website:
http://static.techfuel.net/debug_web2py.png
I'm debugging web2py applications with Eclipse and PyDev. Here is an article:
http://www.web2pyslices.com/main/slices/take_slice/2
Here is an article on debugging python with pdb, which will work with web2py. http://sontek.net/debugging-python-with-pdb
As Carl stated, it is as easy as:
Installing PyDev in Eclipse
Right Click on your Web2Py project, selecting Debug As > Python Run
Selecting web2py.py as the file to run
No other plugins or downloads are needed.
#Ned Batchelder is almost right, but the standard way of doing it in web2py is slightly different.
Instead of `import pdb; pdb.set_trace(), you use the code:
from gluon.debug import dbg
dbg.set_trace()
When executing the web application, the application will freeze when it reaches this section of code. You then go to http://127.0.0.1:8000/admin/debug/interact (using the root URL for your application) and it will show a fully interactive, web based debugger:
See documentation.
Related
When I start a python project in vs code (with the microsoft python extension) it starts "Analyzing in the background" and python keep crashing. It also uses a ton of memory.
Anyone knows how to fix this? Or is it supposed to do this?
This seems to have fixed it for me: https://github.com/Microsoft/vscode-python/issues/4990#issuecomment-477628947
You can disable the new Python Language Server by opening settings in VSCode (Ctrl+, ) and set "python.jediEnabled": true. Then reload the window and/or restart VSCode.
I had the same issue; the only solution that worked for me was to open settings.json (ctrl + Shift + P) and change
"python.languageServer": "Microsoft"
to
"python.languageServer": "Pylance"
Then one gets a pop-up that asks whether one wants to reload the window which one should confirm by pressing "OK".
Then everything works normally again (IntelliJ, autocomplete etc).
As #Vasco pointed out in the comments Microsoft is no longer supported as explained in this thread.
High memory usageļ¼ https://github.com/Microsoft/python-language-server/issues/832
Jedi is an autocompletion tool for Python that can be used in IDEs/editors. Jedi works. Jedi is fast. It understands all of the basic Python syntax elements including many builtin functions. So you can switch Jedi instead of Python Language Server.
Process:
set "python.jediEnabled": true
disable the Visual Studio IntelliCode plugin
delete the .vscode directory
Can solve this by either disabling the extension as suggested in previous answers, or excluding large directories (e.g. containing data) from its search path, by adding to your workspace settings an python.workspaceSymbols.exclusionPatterns key, like so:
settings.json:
{
"python.workspaceSymbols.exclusionPatterns": [
"**/site-packages/**",
"your_pattern_or_directory_to_exclude"
]
}
See also the vscode extension docs.
Here is how I solved this issue:
Go to File > Preferences > Settings > TYPE "python.language server"
If set to 'Microsoft' change your language server to 'Pylance'
Python: Language Server
Define Type of the Language Server
SELECT: Pylance
Reload your Visual Studio Code
Try importing your libraries causing the issues again:
import numpy as np
import pandas as pd
I am using PyCharm to debug a moderately complex Pyramid web application with a lot of dependencies. When I run the application inside PyCharm using PyCharm's Debug run, the application start up slows down significantly. This kills the normal web application workflow of edit, save, refresh. The slowdown is significant, making the application restart to take tens of seconds instead of fractions of seconds.
Is there a way to speed up PyCharm debug runs any way? The similar slowdown would not occur if one is using hardcoded import pdb ; pdb.set_trace() style breakpoints and normal Run mode.
The way to get fast debugging sessions in PyCharm (Professional edition) is to use remote debugging, similar to pdb.set_trace().
In the Run/Debug Configurations dialogue, create a Remote Debug configuration. The dialogue contains the instructions, which I will repeat here completeness sake:
Add pycharm-debug.egg from the PyCharm installation to the Python path.
Add the following import statement:
import pydev
Add the following command to connect to the debug server:
pydevd.settrace('localhost', port=$SERVER_PORT, stdoutToServer=True, stderrToServer=True)
These strings can be copied from the dialogue and pasted into the source. When you choose the host and server port in the dialogue, the pasteable strings will update themselves. Of course, they can also be concatenated to a oneliner using ;.
After the settrace() method has been run, the breakpoints you have set in PyCharm will become active.
So, where's the file pycharm-debug.egg? Somewhere in the near vicinity of the PyCharm binary. In OS X, you will find the file within the Contents/debug-eggs directory within PyCharm.app. I assume other PyCharm distributions have a similar directory.
If you're running the application using a virtualenv, install the egg using easy_install.
If you prefer to run your application within PyCharm (stdout in the PyCharm console is useful), then add the path to the egg file to the Project Interpreter's file paths.
How do you go about debug Blender Python in Eclipse and PyDev?
What I have tried is:
http://www.luxrender.net/wiki/LuxBlend25_Debugging_with_eclipse
http://www.blender.org/forum/viewtopic.php?t=3914&sid=717a127d12596f89e4aea0c54938ef80
But non of then seams to work?
Regards
There is very good e-book written by Witold Jaworski about Blender add-on programming. It includes chapters with step by step instructions how to setup Eclipce with PyDev to debug Blender add-ons.
Programming Add-ons for Blender 2.5
Here is how I setup debug, which is slight different but based on the lux-render tutorial.
First, create the a .py file, lets call it debug.py, which will contain a function which we will call later to setup debugging. Put this file in the same folder as the main __init__.py of your module. As per the lux-renderer tutorial, add the following code, updating PYDEV_SOURCE_DIR.
import sys
def startdebug():
try:
# set the PYDEV_SOURCE_DIR correctly before using the debugger
PYDEV_SOURCE_DIR = 'C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc'
# test if PYDEV_SOURCE_DIR already in sys.path, otherwise append it
if sys.path.count(PYDEV_SOURCE_DIR) < 1:
sys.path.append(PYDEV_SOURCE_DIR)
# import pydevd module
import pydevd
# set debugging enabled
pydevd.settrace(None, True, True, 5678, False, False)
except:
pass
When setting the PYDEV_SOURCE_DIR ensure you point it to the org.python.pydev.debug_xxxxx. There is another folder similiar to this. To ensure you have the correct folder it will contain a /pysrc folder.
Now in your main __init__.py, this must come before any other import statements to work correctly. Add the following directly under the bl_info section, as strangely blender parses this itself.
DEBUGGING = True
if(DEBUGGING):
import debug
debug.startdebug()
Having it here will avoids adding per file traces like the lux-render tutorial.
Add some breakpoint to the version in the add-ons folder,
Switch to the debug perspective,
Start Eclipses debug server,
Start blender
Run the script and it will hit the breakpoint.
The common problems I find people encounter:
pointing the path to the wrong pydev debug folder, ensure that there is a /pysrc folder
When Pydev updates, update the PYDEV_SOURCE_DIR as the debug_xxxxx will have change
not having eclipse server running,
setting breakpoints on a local copy of the files instead of the version in the blender add-on directory
saving the script does not mean that blender will reload it, use imp, disable/renable the add-on or restart Blender.
There are quite comprehensive instructions for setting up blender and eclipse for debugging.
http://wiki.blender.org/index.php/User:Z0r/PyDevAndProfiling
While this is for blenders game engine, much of it applies to regular blender.
I have created a new project in Eclipse, PyDev.
If I were in VS2010, I would mark a project as startup project, and whenever I click F5, it runs.
I want to mark one .py file to be my so called Main, and that each time I click run (F11), it will be the one to run, and not the current that is being edited.
Is it possible?
Go to run -> run configurations
In the menu on the right you should have Python Run option. Create new run configuration by double clicking.
On the right you can select the project you want to run and it's main module. The other tabs can be used to configure arguments, python interpreter used to run the project, etc..
Thanks to #soulcheck, I have found the problem.
It seems that the problem is that Eclipse 3 tries to launch current file instead of the main.
Here is the solution:
Whats the shortcut to Debug in PyDev using Eclipse
I have Eclipse setup with PyDev and love being able to debug my scripts/apps. I've just started playing around with Pylons and was wondering if there is a way to start up the paster server through Eclipse so I can debug my webapp?
Create a new launch configuration (Python Run)
Main tab
Use paster-script.py as main module (you can find it in the Scripts sub-directory in your python installation directory)
Don't forget to add the root folder of your application in the PYTHONPATH zone
Arguments
Set the base directory to the root folder also.
As Program Arguments use "serve development.ini" (or whatever you use to debug your app")
Common Tab
Check allocate console and launch in background
If you'd rather not include your Python installation in your project's workspace to get paster, you can create a pure-Python driver like:
#!/usr/bin/env python
from paste.script.serve import ServeCommand
ServeCommand("serve").run(["development.ini"])
...and run/debug that in Eclipse.
Note: this is running without the --reload option, so you don't get hot deploys (i.e., you'll need to reload server to see changes). Alternatively, you can add the --reload option to get hot deploys, but then Pydev won't stop at your breakpoints. Can't have your cake and eat it too...
ServeCommand("serve").run(["--reload", "development.ini"])
yanjost has it right, just wanted to add that you need to make sure you do not use the --reload option, this will prevent the debugger from properly attaching itself and cause your breakpoints not to work. Just a little thing I ran in to.
I was able to get --reload working by changing the 'Working directory' in the arguments tab to not use default (i.e. select 'Other'->File System->'Root of your Pylons' app where development.ini is stored.
On linux that will probably be /usr/bin/paster or /usr/local/bin/paster for paste script, and for arguments i have: serve ${workspace_loc}${project_path}/development.ini
I also got this working (finally). I used buildout instead of virtualenv to install pylons (instructions at: http://wiki.pylonshq.com/display/pylonscommunity/Howto+install+Pylons+with+buildout), so the instructions above needed to be changed a little as far as the paths go.
-for "Main Module", I use:
${workspace_loc:myeclipseprojectname/bin/paster}
(adding --reload made breakpoints not work for me, and I tested this a couple times)
-for "Program Arguments", I use:
serve ${workspace_loc:myeclipseprojectname/mypylonsprojectname/development.ini}
-for "Working Directory, Other:", I use:
${workspace_loc:myeclipseprojectname/mypylonsprojectname}
-as mentioned above, in "Common Tab", "Check allocate console and launch in background"
-and remember to set a breakpoint before trying.
This doesn't really answer question about how to do it in eclipse. But I've been debugging paster server with winpdb, which is quite nice graphical python debugger (you can install it with easy_install winpdb).
Just start your server e.g.:
winpdb /usr/local/bin/paster serve development.ini
And click run button.
As wayne said, it's necessary to not use --reload option. At least I wasn't able to find how to attach to actual webapp even, when selecting to which forked process debugger should enter (entering different processes can be controlled with "fork parent" and "fork child" debugger commands).