Is there such a thing as startup file in PyDev under Eclipse? - python

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

Related

How can I make .py files run using Python Shell by default?

I made a Python GUI using Tkinter, but when I run it directly (double click the file) it opens the black python window but automatically closes by itself in less than half a second. I found a way to make it open the IDLE editor but it just opens the editor and doesn't run it.
I want it to run the way it runs when you open the IDLE editor and press Run Module. This runs it using Python Shell.
Is there a way I can make it automatically run using Python Shell?
Based on Mark Tolonen's comment you should do two things
rename your file to a .pyw from .py to prefer console-less runs
set your system to open .pyw files with pythonw if that's not configured already
Linux: configure xdg-open
Windows: right click and choose an application from the context menu (you may need to find where Python is installed to select the pythonw.exe executable)
Okay, one of the comments on the original question is correct.
As Terry Jan Reedy (user:722804) said,
It is possible that your mygui.py file is missing 'root.mainloop()' or the equivalent to start the GUI. IDLE lets you omit that during development so that one can interact with tkinter to retrieve values and make changes to widgets.
Adding gui.mainloop() to the end of my program worked.

How to run code in Pycharm

If I go to "tools" and select "python console", and enter several lines of code, how do I execute this? If my cursor is at the end of the script, I can just hit enter. But how can I run the code using keyboard shortcuts if the cursor is not at the end? In Spyder this is done using shift+enter, but I can't figure out how to do it here. I've seen places say control+enter, but that doesn't work. Thanks!
If you use Win 10, 64Bits. Run your codes using Ctrl + Shift + F10 or simply right click on the workspace and click Run from the options.
in mac.
you can use fn+shift+f10 and happy coding with python
From Jetbrains' official documentation:
PyCharm suggests several ways to run a script opened in the editor:
First, you can use the keyboard shortcut ⌃⇧R
Second, you can use the context menu command (here Run Solver), invoked by right-clicking the editor background
Use the main menu Run | Run, Run | Run 'Solver'
Finally, it is possible to run a script from the main toolbar, using the temporary run/debug configuration Solver
Right click on project name / select New / select Python File
Pycharm needs to know you're running a Python file before option to run is available

Is it possible to debug run a script inside pydev without creating a dedicated project

Pydev has awesome Python debugging features - stepping through the code, visual variable inspection...
Creating a python script file is a relatively quick and easy process in contrast with the bureaucracy that involves creating a full-blown pydev project.
Is it possible to skip the step of project creation when I want to debug a single file python script?
If I just start to debug a script, I get the following error:
Strange, I can't really reproduce the issue on the '#'.
Still, you do need to have at least the interpreter and one project configured... then, if you open an external file you can just use F9 to create a new launch configuration for it / specify that project to run.
Afterwards, if you specified things as http://pydev.org/manual_101_run.html suggests, you can just use F11 to debug that run configuration or Ctrl+F11 to rerun it.

Execute a default .py file in PyDev

I'm doing a Python project in Eclipse with PyDev. I have a "main" file and some "class" files. I primarily work in the classes, but I need to execute the code via the main file.
At the moment I need to either switch to the main file, or use the drop down menu of the run/debug-button to execute the main file. Pressing the button or using F11, just runs the class file (which is useless)
Is there a way to let PyDev always run a specific file in a project, or perhaps always run the last file executed (which probably will be the best solution).
Thanks in Advance :)
Surely (relaunching the last launch was actually the default in in Eclipse 3.2, never understood why they changed that)...
You can have that back in the preferences at: window > preferences > Run/Debug > Launching and set the Launch Operation to Always launch the previously launched application.
So, Ctrl+F11 will relaunch the last launch and F11 will debug the last launch...
And to launch the file initially you may:
Use a shortcut: F9 to run the current opened file
Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc).
If you are using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the current module (and even selecting which tests should be run).
Relaunch some other launch you did previously: Alt + R + T and choose a previous launch to relaunch.
You may also launch in unit-test mode all files beneath a folder by right clicking the folder > run as > Python unit-test
(reference: http://pydev.org/manual_101_run.html)
And if you use unit-tests, you may also want to take a look at: Continuous unit testing with Pydev (Python and Eclipse)

How to debug Web2py applications?

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.

Categories

Resources