Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch and debug a single script in PyDev

Tags:

eclipse

pydev

I am a beginner in using Eclipse and PyDev (Aptana Studio 3). I am not used to and i don't understand the workflow in such big IDEs as Eclipse.

I have a simple task: i have a simple Python script, which i want to open and run in Eclipse, having its output in Eclipse console. Or debug it.

Until now i used another IDE called Eric4, which allowed me to do what i want - open a file and run immediately, without creating a project or setting up launch configurations.

Is this possible in Eclipse, or i have to create a project for each file i want to run or debug? I want to understand how it works.

I guess i understand that creating a project is needed at least for settings up the paths (PYTHONPATH), but if it's a single script - somehow to use by default the current directory?

For example i have a folder called snippets where i keep a lot of python scripts which demonstrate some functionality. How do i open these files one by one and run them?

Most of my coworkers launch python scripts in a separate console - python my_scipt.py.

like image 844
warvariuc Avatar asked Sep 06 '11 13:09

warvariuc


People also ask

How do I run and debug a Python script?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally, and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().

How do I use PyDev debugger?

Use Ctrl+F10 to open the context-menu and then select Add Breakpoint; Right-click the left bar to open the context-menu and then select Add Breakpoint; Use Ctrl+Shift+B to toggle the breakpoint in the line (if it doesn't work, go to the customize perspective and enable Breakpoints in Action Set Availability.

How do I run code in PyDev?

Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc). Note: if you were using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the module (and even selecting which tests should be run -- and if Shift is pressed it's launched in debug mode).

How do I debug a Python script in Eclipse?

To open the debugger, you need to open the “Debug” perspective. You can do this by selecting “Window → Open Perspective → Other…” from the main menu. In the popup window that appears, select “Debug” and click on the “OK” button.


1 Answers

You need to have at least one project with the configuration you want (i.e.: syntax type, interpreter), then, open the file you want to run and press F9.

If it's an external file -- i.e.: a file that's not under a project in Eclipse -- it'll ask you to associate a project with the launch to get the needed information for the launch, but the file doesn't really have to be in the project (note that you can drag external files from your filesystem into Eclipse to open them).

I suggest you follow the steps on the getting started: http://pydev.org/manual_101_root.html (it guides you to configuring PyDev and explains how to do a run/debug session).

like image 149
Fabio Zadrozny Avatar answered Oct 13 '22 22:10

Fabio Zadrozny