使用Eclipse PyDev运行外部Python程序 [英] Run External Python Programs with Eclipse PyDev

查看:371
本文介绍了使用Eclipse PyDev运行外部Python程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PyDev启用的重构,但是认为在我的Eclipse工作区中为我创建的每一个小Python脚本创建一个项目文件夹是有点可笑。



我可以通过使用 File>>在Eclipse中编辑文件来重构。打开文件... 。但是,我还是要去终端来运行文件。在Eclipse中运行它是很好的。



我已经尝试设置了一个 Run>外部工具>外部工具配置... 使用位置

  / Library /框架/ Python.framework /版本/当前/ bin / python 

参数

  $ {resource_loc} 

可能,这将使用打开的文件调用python解释器。但是没有。我得到的是:

 变量引用空选择:$ {resource_loc} 
/ pre>

此StackOverflow问题有与我一样的问题,但所选答案与空的 $ {resource_loc} 问题无关。



如何在Eclipse中运行外部python程序?

解决方案

最新的PyDev已经改进了一些位...处理外部文件的用例的工作流程如下(检查PyDev 2.2.2和Eclipse 3.7):


    将文件从文件系统拖到Eclipse(应打开文件进行编辑)。


  1. 按F9键,编辑器打开运行文件...它仍然会要求您解决PYTHONPATH和解释器使用的项目(您可以使用任何具有该解释器的项目你想要用于运行,或者创建一个PyDev项目为'external_projects',并将这些运行绑定到它)。


请注意,您需要使PyDev已正确配置(步骤可从以下网址获取: http://pydev.org/manual_101_root.html ),如果您按照步骤标记重新运行上次启动的默认值 - http:// pydev.org/manual_101_run.html - 按Ctrl + F11将重新运行上次再次启动(您不再需要将该编辑器作为活动的)。



您可以稍后在菜单中运行配置的更改:运行>运行配置。


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?

解决方案

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.

这篇关于使用Eclipse PyDev运行外部Python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆