前提
官網上提供了 Mac 和 Windows 上的安裝包和 Linux 上安裝所需的源碼。
下載網址如下:
https://www.python.org/downloads/release/python-360/
安裝
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz 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
測試幾個新的語法特性:1.
# 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>]
原因是 readline 庫沒有安裝。
sudo apt-get install libreadline-dev
cd Python-3.6.0 ./configure make sudo make install