Eclipse PyDev使用远程解释器

11

有没有可能让eclipse PyDev使用远程Python解释器?

我想这样做,因为我要连接的Linux服务器有几个优化求解器(CPLEX、GUROBI等)正在运行,而我的脚本需要用到它们。

目前我在本地使用eclipse编写脚本,然后将所有文件复制到远程机器上,使用ssh登录并在那里执行脚本"python script.py"。 相反,我希望点击"运行"按钮,并在我的eclipse IDE中执行所有内容。

谢谢


你可以在这个 Stack Overflow 问题中查看我的答案。 - tomasyany
2个回答

9

很遗憾,否定的答案。您可以通过远程系统资源管理器(RSE)远程连接到Linux服务器,但无法将其用作远程解释器。我使用的是Pycharm。您可以使用免费的社区版或专业版,需要付费购买。它不是非常昂贵,而且一直以来都运行得很好。


6
如Adel所说,使用远程系统浏览器或普通的运行按钮可能无法实现此功能,但是您可以自动化当前使用的过程。当我的笔记本电脑风扇坏了,在那里进行任何重要计算会导致过热和关机时,我不得不这样做了几个星期,我只是在我的工作机器上运行一切。
您可以使用外部工具机制运行一个短的脚本,将您的代码同步到远程服务器,运行您的脚本,然后将任何输出文件同步回到本地机器。我的脚本看起来像这样,存储在$HOME/bin/runremote.sh中,并且是可执行的(chmod +x runremote.sh
fp="$1"  # Local path to the script we want to run--for now,
         # this is the only command I pass in from Eclipse, but you could add others if so inclined.
# My home directory is a little different on my local machine than on the remote,
# but otherwise things are in the same place. Adjust as needed.
fp=`python -c "print '$fp'.replace('/home/tsbertalan', '/home/oakridge/bertalan')"`

# Run the synchronization. I use Unison, but you could use something else,
# like two calls to rsync, or a series of scp commands.
reposync >/dev/null  # The redirection assumes your sync command will print errors properly on stderr.
cd='cd '`dirname $fp`

# I use a virtual environment on the remote server, since I don't have root access to install
# packages globally. But this could be any set-up command you want to run on the remote.
# A good alternative would be `source $HOME/.profile` or `~/.bashrc`.
act='source /home/oakridge/bertalan/bin/activate'
fname="`basename $fp`"
cmd="$act ; $cd ; python $fname"

# Run the command remotely. The -X forwards X11 windows, so you can see your Matplotlib plots.
# One difficulty with this method is that you might not see all your output just as it is created.
ssh bertalan@remote.server.edu -X  "$cmd"
sleep 1

# My synchronization script is bidirectional, but you could just use rsync with the arguments flipped.
reposync >/dev/null

如果你在本地没有使用 Linux 或 OSX,则可能需要使用 MinGW 或 Cygwin(或其他工具)才能使其工作。或者,由于您似乎已经有一个可用的 Python 解释器,您可以编写等效的 Python 脚本,在资源管理器中通过文件属性对话框使它可执行,并在开头添加 #!/path/to/python 行。我不经常使用 Windows,所以无法提供太多帮助。
要在 Eclipse 中使用此功能,请转到 Run > External Tools > External Tools Configurations... 。添加一个新工具,其位置为您脚本的路径,第一个参数为 ${resource_loc}。然后您可以通过 Run > External Tools > [第一项] 使用它,或通过转到 Windows > Preferences > Keys 并搜索 "Run Last Launched External Tool" 将其绑定到键盘快捷键上(我使用了 F12)。大概需要先通过菜单将其设置为“最后启动”的外部工具。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接