Run External Python Programs with Eclipse PyDev

本秂侑毒 提交于 2019-12-29 06:56:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7194424/run-external-python-programs-with-eclipse-pydev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!