鍍金池/ 問(wèn)答/Python  iOS/ mac上安裝python3,但是在終端輸入python3還是顯示python2?

mac上安裝python3,但是在終端輸入python3還是顯示python2?

圖片描述

Last login: Mon Dec 25 19:20:52 on ttys000
lucasdeMacBook-Pro:~ lucas$ python
Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'python3' is not defined
>>> 
回答
編輯回答
命多硬

先ctrl+D退出.

輸入python3 運(yùn)行CPython解釋器

建議不要用終端.

用自己熟悉的編輯器或者IDE寫代碼: yourfile.py

在文件目錄路徑下輸入 python3 yourfile.py 來(lái)運(yùn)行.

2018年8月20日 18:08
編輯回答
笨尐豬

lucasdeMacBook-Pro:~ lucas$ python3 這樣就可以了

2017年9月24日 23:11
編輯回答
冷咖啡

你已經(jīng)進(jìn)入了python終端了。先輸入 quit() 退出,然后再輸入 python3。

2018年4月8日 04:55
編輯回答
裸橙

你這不是已經(jīng)進(jìn)入python終端了麼,進(jìn)入python終端之后輸入python3,提示你python3變量未定義,和你切換python版本沒(méi)關(guān)系。

要在進(jìn)入python終端之前,在cmd模式下輸入python3,這樣就進(jìn)入python3的終端了。

2018年8月27日 00:12
編輯回答
卟乖

兄dei,你現(xiàn)在是在python2里面啟動(dòng)python3啊,2333333......

2018年2月16日 06:36
編輯回答
蝶戀花

大兄弟 文件執(zhí)行錯(cuò)了 你執(zhí)行的是python2的 如果是brew安裝的可以用 brew info python查看下執(zhí)行路徑

2018年5月31日 16:18
編輯回答
還吻

太粗心

這樣容易產(chǎn)生很難修復(fù)的bug

2018年2月1日 19:10
編輯回答
青瓷

我使用anaconda

?  Desktop python
Python 3.6.3 |Anaconda, Inc.| (default, Oct  6 2017, 12:04:38)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
2017年3月20日 22:08
編輯回答
毀了心

沒(méi)錯(cuò)的,按照python不會(huì)替換到系統(tǒng)默認(rèn)的python2,也不建議刪除mac自帶的python2,系統(tǒng)底層很多軟件依賴python2,可以在終端輸入python3啟動(dòng)python3

2017年6月16日 18:27
編輯回答
久愛她

系統(tǒng)默認(rèn)使用的是Python2,使用which python找到python位置,
看看鏈接是不是指定到了你新安裝的python路徑啊。

2018年8月13日 02:56