1. 程式人生 > >在ubuntu16上安裝Python3.6.0

在ubuntu16上安裝Python3.6.0

$:   xz -d Python-3.6.0.tar.xz

$:   tar -xvf Python-3.6.0.tar

$:   cd Python-3.6.0

$:   ./configure

$:   make

$:   sudo make install

測試使用

$:   python3.6 --version

Python 3.6.0

測試幾個新的語法特性:

Formatted string literals

name = 'Ray' f"Hello {name}." 'Hello Ray.' 效果相當於

name = 'Ray' "Hello {name}.".format(name=name) 'Hello Ray.'

Underscores in Numeric Literals

a = 1_000_000_000_000_000 a 1000000000000000

'{:_}'.format(1000000) '1_000_000''1_000_000'

Enum.auto

from enum import Enum, auto class Color(Enum): ... red = auto() ... blue = auto() ... green = auto() ...

list(Color) [<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>]

Tips

第一次編譯安裝之後,有可能會發現輸入python3.6 之後,方向鍵失效。 原因是 readline 庫沒有安裝。

解決方式:

安裝 readline 庫

$:   sudo apt-get install libreadline-dev 安裝之後,再將 python 重新編譯安裝一次。

$:   cd Python-3.6.0

$:   ./configure

$:   make

$:   sudo make install