【问题标题】:Eclipse PyDev use remote interpreterEclipse PyDev 使用远程解释器
【发布时间】:2013-01-20 22:03:04
【问题描述】:

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

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

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

谢谢

【问题讨论】:

标签: eclipse pydev python


【解决方案1】:

很遗憾,没有。您可以通过远程系统资源管理器 (RSE) 远程连接到您的 Linux 服务器。但不能将其用作远程解释器。我使用 Pycharm。您可以使用需要付费的免费社区版或专业版。它并没有那么贵,而且对我来说效果很好。

【讨论】:

    【解决方案2】:

    正如 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 > [first item] 一起使用,或将其绑定到键盘快捷键(我使用 F12) 转到 Windows > Preferences > Keys,然后搜索“Run Last Launched External Tool”。想必你会 必须先浏览菜单才能使其成为“最后启动”的外部工具。

    【讨论】:

      猜你喜欢
      • 2012-06-16
      • 2015-09-07
      • 2011-05-02
      • 2011-01-29
      • 2011-08-01
      • 2013-11-22
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多