Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run External Python Programs with Eclipse PyDev

I want to use the refactoring enabled by PyDev but think it is a little ridiculous to create a project folder in my Eclipse workspace for every single little python script I create.

I'm able to get refactoring by editing the file in Eclipse using File > Open File.... However, I still have to go to the Terminal to run the file. It would be nice to just run it in Eclipse.

I've tried setting up a Run > External Tools > External Tools Configurations... using the Location

/Library/Frameworks/Python.framework/Versions/Current/bin/python

and the Arguments

${resource_loc}

Presumably, this would call the python interpreter using the opened file. But it doesn't. All I get is:

Variable references empty selection: ${resource_loc}

This StackOverflow question has the same problem as I do, but the selected answer has nothing to do with the empty ${resource_loc} problem.

How do I run external python programs in Eclipse?

like image 863
Chris Redford Avatar asked Aug 25 '11 17:08

Chris Redford


1 Answers

The latest PyDev already has improved things a bit... the workflow for the use-case of dealing with external files is the following (checking on PyDev 2.2.2 and Eclipse 3.7):

  1. Drag file from filesystem to Eclipse (should open the file to edit it).

  2. Press F9 with the editor open to run the file... It'll still ask you for a project to resolve the PYTHONPATH and interpreter to be used (you can probably just use any project you have that has the interpreter you want to use for the run or create a PyDev project as 'external_projects' and bind those runs to it).

Note that you need to have PyDev already properly configured (steps available at: http://pydev.org/manual_101_root.html ) and if you followed the step to mark the rerun the last launch as the default -- http://pydev.org/manual_101_run.html -- pressing Ctrl+F11 will rerun that last launch again (and you no longer need to have that editor as the active one).

You may later on change that run configuration in the menu: Run > Run configurations.

like image 87
Fabio Zadrozny Avatar answered Oct 06 '22 05:10

Fabio Zadrozny