
我正在嘗試Python
使用 編寫一個簡單的腳本Geany
。這個IDE會自動編譯我寫的程式碼,但我不確定Python
它使用的是哪個版本。如果我python --version
在命令列中輸入,我會得到:
Python 2.7.3
但如果我輸入python3
我會得到:
Python 3.2.3 (default, Oct 19 2012, 19:53:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Ubuntu 有兩個版本嗎?如果是的話,用哪一個Geany
來編譯?
答案1
Ubuntu 有兩個版本,是的。該python
命令將總是指向 Python 2.x 版本,並且python3
將始終指向預設的 Python 3.x 版本。該python
命令將絕不指向Python 3.x。
我不確定 Geany 到底使用什麼,但我懷疑它在它生成的腳本中使用 Python 2.x (因此可能會放置#!/usr/bin/python
(或者應該放置,如果它使用的話)。/usr/bin/env python
答案2
嘗試import sys;print(sys.version_info)
從 geany 內部運行。
答案3
您可以使用:
import sys
print sys.version
找出您正在運行的 python 版本。
當然,由於 python 3 中的變更print
現在是一個函數,因此這不適用於版本 3。
import sys
print(sys.version)