繁体   English   中英

Eclipse PyDev使用远程解释器

[英]Eclipse PyDev use remote interpreter

是否有可能使eclipse PyDev使用远程Python解释器?

我想这样做,因为我要连接的Linux服务器有几个运行的优化解算器(CPLEX,GUROBI等),我的脚本使用。

目前我在本地使用eclipse编写脚本,然后将所有文件复制到远程机器,使用ssh登录并使用“python script.py”执行脚本。 相反,我希望单击“运行”按钮,只需在我的eclipse IDE中执行所有操作。

谢谢

抱歉不行。 您可以通过远程系统资源管理器(RSE)远程连接到Linux服务器。 但不能将它用作远程解释器。 我用Pycharm。 您可以使用您必须为其付费的免费社区版或专业版。 它并不昂贵,它对我来说很有用。

正如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中使用它,请转到运行>外部工具>外部工具配置....添加一个新工具,其位置是脚本的路径,其第一个参数是$ {resource_loc}。 然后,您可以在运行>外部工具> [第一项]中使用它,或者通过转到Windows>首选项>键,然后搜索“运行上次启动的外部工具”将其绑定到键盘快捷键(我使用F12)。 据推测,您必须首先浏览菜单才能使其成为“最后推出”的外部工具。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM