0
0

VSCode上でリモートPCで動作するpythonをデバッグ pythonの実行ファイルを変更したい

Last updated at Posted at 2023-11-07
  1. remote explorの設定

login_name@ip で接続

  1. Windows上で使っているVSCodeからRemote ExploerでリモートPCを開く。

  2. VSCode上からpythonスクリプトを実行するとpythonライブラリが無いと怒られる。しかし、リモートPC上ではそのようなエラーにはならず正常に終了する。

  3. 2.でVSCodeから実行した際のログを見ると、/usr/bin/pythonを使っている。リモートPCでも/usr/bin/pythonを使ってPythonスクリプトを実行するとVSCodeと同じエラーになる。/usr/share/miniconda3/bin/python3を使うと正常に実行できることが分かった。

  4. launch.json を開く

image.png

  1. launch.json に "python": "/usr/share/miniconda3/bin/python3" を追加することで期待通りに動作した。
    launch.json
{
	// Use IntelliSense to learn about possible attributes.
	// Hover to view descriptions of existing attributes.
	// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Python: Current File",
			"type": "python",
			"request": "launch",
			"python": "/usr/share/miniconda3/bin/python3",
			"program": "scripts/generate_model.py",
			"console": "integratedTerminal",
			"justMyCode": true
		}
	]
}
  1. (疑問点) 4. の後も、VSCode上ではなぜか、/usr/bin/pythonを使っているようなログになっている。しかし、スクリプトは/usr/share/miniconda3/bin/python3を使って動作させた際と同じに動く。

  2. 引数の設定

argsを設定する

{
	// Use IntelliSense to learn about possible attributes.
	// Hover to view descriptions of existing attributes.
	// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Python: Current File",
			"type": "python",
			"request": "launch",
			"python": "/usr/share/miniconda3/bin/python3",
			"program": "scripts/generate_model.py",
			"console": "integratedTerminal",
			"args": [
				"--model_name=add"
			],
			"justMyCode": true
		}
	]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0