0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

sudo python my_script.py で sudo: python: command not found となる場合の対処方法

Posted at

環境

  • Ubuntu 20.04.2 LTS (Focal Fossa)
  • Python 3.8.5
  • venv 環境

理由

パスの設定が上書きされ、Pythonコマンドがみつからなくなるため。

Your /etc/sudoers is explicitly configured to override your user's path with a known, secure one.
*1 より

対処方法

[方法1] .bachrc にパスを引き継いで実行するコマンドを新設する

.bachrc
psudo() { sudo env PATH="$PATH" "$@"; } 
command
psudo python my_script.py

[方法2] パスを引き継ぐように実行時のコマンドを編集する

command
sudo env "PATH=$PATH" python my_script.py

参考資料

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?