11

Eclipse PyDev にリモート Python インタープリターを使用させる可能性はありますか?

接続したいLinuxサーバーには、スクリプトが使用するいくつかの最適化ソルバー(CPLEX、GUROBIなど)が実行されているため、これを実行したいと思います。

現在、Eclipse をローカルで使用してスクリプトを記述し、すべてのファイルをリモート マシンにコピーし、ssh を使用してログインし、そこで「python script.py」を使用してスクリプトを実行します。代わりに、「実行」ボタンをクリックして、Eclipse IDE 内ですべてを実行したいと考えています。

ありがとう

4

2 に答える 2

9

残念だけど違う。Remote System Explorer (RSE) を介して Linux サーバーにリモート接続できます。ただし、リモート通訳者としては使用できません。私はPycharmを使用しています。無料の Community Edition または有料の Professional Edition を使用できます。それほど高価ではなく、私にとってはうまく機能しています。

于 2013-03-12T12:16:18.763 に答える
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} である新しいツールを追加します。次に、実行>外部ツール> [最初の項目]で使用するか、Windows>設定>キーに移動して「最後に起動した外部ツールを実行」を検索して、キーボードショートカット(私はF12を使用)にバインドできます。おそらく、これを「最後に起動した」外部ツールにするために、最初にメニューを確認する必要があります。

于 2014-07-21T14:26:24.123 に答える