簡體   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