Linuxサーバー

Ubuntuでも 18.04以降は Python 2系ではなく、3系がデフォルトでインストールされているので、
Python3を使おうと思ったら、新し目の Ubuntuをインストールするのが、手っ取り早くて確実。

でも、私のように 32bitのマシンしか持ってない場合、Ubuntuのサポートは 16.4 までなので、
デフォルトでは Python2.7 とかになってしまう。
なので、Python2 がデフォルト・インストールの環境に Python3 をインストールするときのメモ。

(1) gitをインストールする
Pyenv のインストールに必要なため、まずは gitをインストール。

$ sudo apt-get install git

(2) gitからPyenvのインストーラを取得
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Pyenvにパスを通して有効化します。
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
Pyenvのバージョンを確認します。
$ pyenv -v
pyenv 1.2.8

(3) 目的のバージョンの Python をインストール
pyenv を使って、目的のバージョンのpythonをインストールする。

$ pyenv install 3.7.0
Downloading Python-3.7.0.tar.xz...
-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Installing Python-3.7.0... 

BUILD FAILED (Ubuntu 18.04 using python-build 1.2.12-2-geb68ec94)

Inspect or clean up the working tree at /tmp/python-build.20190706061507.17491
Results logged to /tmp/python-build.20190706061507.17491.log

Last 10 log lines:
~~ 中略 ~~
checking for cl.exe... no
configure: error: in `/tmp/python-build.20190706061507.17491/Python-3.7.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

おっと、Cコンパイラが入ってなかった。。
その後、make やいろんなライブラリが足りないことが判明。
追加でインストールする。

$ sudo apt-get install gcc make zlib1g-dev libffi-dev bzip2

$ pyenv versions

system (set by /home/user/.pyenv/version)

 3.7.0

Python 3.6.7がインストールされたことを確認します。
$ pyenv versions

system

 3.6.7

Python 3.6.7を有効化します。
$ pyenv local 3.6.7
$ pyenv versions

 system

3.6.7 (set by /vagrant/.python-version)


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS