osprey's diary

日々の雑感を書き綴ります

python3.7.0rc1をtarballから入れてみた

python3.7を触ってみたかった。今回はtarballから。OSはDebian9.4。

prefixでバージョン分けてたけど、今回は違うやり方を試してみる。

元ネタはこちら

 

必要そうなパッケージはあらかじめ入れておく

# apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

 

公式サイトからダウンロード

# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0rc1.tar.xz

 

展開して

# tar Jxvf Python-3.7.0rc1.tar.xz

 

READMEを読む

# less EADME.rst

 

helpも見ておく

# ./configure --help

 

 

configureして

# ./configure --enable-optimizations --with-ensurepip=install

 

makeしてインストールする

makeは-jでjobを並列で走らせると、環境によって早く終わるみたい

ちょっと古いけどこちらが分かりやすかった

manでみても-jは変わってない感じかな

# make -j8 && make altinstall

 

update-alternativesでバージョン切り替え管理できる

ちょっと古いけどこちらが分かりやすかった

# update-alternatives --install /usr/bin/python python /usr/local/bin/python3.6 50
# update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 60
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 80
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 30

必要な時だけ3系に切り替えるのが良いと思う

切り替えるときはこんな感じ

# update-alternatives --config python
There are 4 choices for the alternative python (providing /usr/bin/python).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python2.7 80 auto mode
* 1 /usr/bin/python2.7 80 manual mode
2 /usr/bin/python3.5 30 manual mode
3 /usr/local/bin/python3.6 50 manual mode
4 /usr/local/bin/python3.7 60 manual mode

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

 

 そして早速3.7にしたの忘れててうっかりaptでパッケージインストールしようとして嵌ったorz

そもそも開発するときはvenvで環境分けるから必要なかった。すみませんupdate-alternatives使ってみたかっただけでした。

やっぱり基本に立ち返ってprefixでinstall directory分けて必要な時だけvenvで環境作るのが落ち着くかな。。。