# Python3.7のインストール

**URL:** https://forum.ficusonline.com/t/topic/322
**Category:** Linux
**Created:** [2019 年 9 月 21 日午前 5:07 UTC](https://forum.ficusonline.com/t/topic/322 "2019-09-21T05:07:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2019 年 9 月 21 日午前 5:07 UTC](https://forum.ficusonline.com/t/topic/322/1 "2019-09-21T05:07:50Z")

</div>

Ubuntu18.04サーバのpython3バージョンは3.6の為、最新版3.7をインストールします。  
"python3"コマンド入力の際、この最新バージョンが選択されるように"update-alternatives"コマンドで指定します。

> **[How to upgrade to python 3.7 on ubuntu 18.10 - jcutrer.com](https://jcutrer.com/linux/upgrade-python37-ubuntu1810)**
>
> Ubuntu 18.10 ships with python 3.6.7, here is how to install python 3.7 and configure it as the default version of python Before getting started, run the following command to see what version of python3 you are running. python3 -VPython 3.6.7 NOTE:...

上記参照元にも注意書きがありますが、デスクトップ環境でpython3のリンク先を変更した場合、3.6と関連する一部GUIアプリに影響が出る可能性が有ります。

**python3.7インストール**

```auto
$ sudo apt-get install python3.7 python3-venv python3.7-venv python3.7-dev

```

**python3バージョン登録**

```auto
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2

```

**python3バージョン選択**

```auto
$ sudo update-alternatives --config python3

There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.7 2 auto mode
  1 /usr/bin/python3.6 1 manual mode
  2 /usr/bin/python3.7 2 manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

```

**python3のバージョン確認**

```auto
$ python3 --version
Python 3.7.3

```

直接バージョンを指定してpythonコマンドを実行することも出来ます。

```auto
$ pyhon3.6 --version

```

---

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2021 年 3 月 24 日午前 5:38 UTC](https://forum.ficusonline.com/t/topic/322/2 "2021-03-24T05:38:25Z")

</div>

**Pythonエラー対応**

python起因のapt関連エラー

[https://stackoverflow.com/questions/13708180/python-dev-installation-error-importerror-no-module-named-apt-pkg](https://stackoverflow.com/questions/13708180/python-dev-installation-error-importerror-no-module-named-apt-pkg)

```auto
$ python -V
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 28, in <module>
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

```

以下パッケージをインストール

```auto
$ sudo apt-get install python3-apt pyhon3-pip

```
