3
3

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 5 years have passed since last update.

bashでPythonのバージョン指定を行う

Last updated at Posted at 2019-05-14

ubuntu等のLINUXにはデフォルトでpythonの2系がインストールされているが、PythonとOpenCVの互換性の面からPythonの3系を使いたい場合がある。
しかし、Pythonのデフォルトは2系になっているため、3系をメインで使いたい場合、デフォルトにしておくと便利である。今回は、Pythonの2系から3系をデフォルトにする方法を説明する。

バージョンの確認

ターミナルで$pythonでPythonを起動するとデフォルトに設定されているバージョンが立ち上がる。

環境変数の設定をする

環境変数の設定を行う場合、'bash'に記述する。bashには、'bash_profile'と'bashrc'があり、このファイルに設定を記述することで使用環境をユーザ好みにカスタマイズできる。
'bash_profile'はログイン時に一回実行される設定で'bashrc'はシェルの起動時に一回実行されるといった特徴があり、今回は'bashrc'に記述をする。
まずは
$which python3
でPythonの3系がインストールされている場所のパスを確認する。
次に、
$vi ~/.bashrc
で設定ファイルを開き、好きな場所に
alias python = 'Pythonの3系がインストールされている場所のパス'
を記述する。
最後に、
$source ~/.bashrc
で設定を反映させる。

設定をしたら再び、
$python
でPythonを起動し3系が立ち上がれば設定完了です。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?