LoginSignup
0
0

More than 3 years have passed since last update.

他の人が作ってくれたCloud9でPythonのバージョンが古い時の対応方法

Posted at
  • 環境 : Cloud9
    • 同僚がEC2を利用したCloud9を使っていたので、私も使ってみたくてそのCloud9にアカウントを作ってもらって早速使い始めた。

事象 : Pythonのバージョンが古かった

# Pythonが3じゃない!
$ python --version
Python 2.7.18
# pipは・・・なぜかPython3.6のもの?
$ pip --version
pip 20.2.4 from /home/ec2-user/.local/lib/python3.6/site-packages/pip (python 3.6)
# Python3はあるようだ・・・
$ python3 --version
Python 3.6.12

Cloud9のPythonを3にすればよいのか?と思ったらもうなっている・・・

# 「+」がPython3にくっついている・・・けどとりあえず選択してみる
$ sudo update-alternatives --config python

There are 3 programs which provide 'python'.

  Selection    Command
-----------------------------------------------
*  1           /usr/bin/python2.7
 + 2           /usr/bin/python3.6
   3           /usr/bin/python2.6

Enter to keep the current selection[+], or type selection number: 2
# Python3にならない・・・
$ python -V
Python 2.7.18

原因 : .bashrcで古いバージョンを指定しているから

# 自分のアカウントのPythonが2になっている・・・
$ alias | grep python
alias python='python27'
# aliasでPython2.7が設定されている・・・
$ cat ~/.bashrc | grep python
alias python=python27

対応 : .bashrcで指定するPythonのバージョンを変える

# .bashrcじゃなくても読込順序が後のファイルならOK
$ ls -la
# ...省略...
-rw-r--r--  1 ec2-user ec2-user  336 Jul 24  2019 .bash_profile
-rw-r--r--  1 ec2-user ec2-user 1401 Nov 20 06:48 .bashrc
-rw-rw-r--  1 ec2-user ec2-user  118 Jul 24  2019 .zshrc

# viで開いてaliasでPython3.6を指定して
$ vi ~/.bashrc
$ cat ~/.bashrc | grep python
alias python=python36

# 反映すると
$ source ~/.bashrc 
function

# Python3.6になった・・・
$ python --version
Python 3.6.12
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