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

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

问题描述

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

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.

我可以通过在 Eclipse 中使用 File > 编辑文件来进行重构.打开文件....但是,我仍然必须到终端才能运行该文件.最好在 Eclipse 中运行它.

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.

我试过设置一个 Run >外部工具外部工具配置... 使用位置

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

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

参数

${resource_loc}

据推测,这将使用打开的文件调用 python 解释器.但事实并非如此.我得到的是:

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}

这个 StackOverflow 问题 和我有同样的问题,但是选择的答案与空 ${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.

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

How do I run external python programs in Eclipse?

推荐答案

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

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. 将文件从文件系统拖到 Eclipse(应打开文件进行编辑).

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

在打开编辑器的情况下按 F9 以运行文件...它仍然会要求您提供一个项目来解析要使用的 PYTHONPATH 和解释器(您可能只使用您拥有的任何项目您想用于运行的解释器或创建一个 PyDev 项目作为external_projects"并将这些运行绑定到它).

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).

请注意,您需要已正确配置 PyDev(步骤位于:http://pydev.org/manual_101_root.html ) 并且如果您按照步骤将上次启动的重新运行标记为默认 - http://pydev.org/manual_101_run.html -- 按 Ctrl+F11 将再次重新运行上次启动(并且您不再需要将该编辑器作为活动编辑器).

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天全站免登陆