天天看點

Pycharm 增加 Python3的路徑

Pycharm預設的Python是python2,但是如果代碼是python3寫的,就需要在pycharm裡的project interpreter增加python3

注意,一定要找到Project Interpreter,這裡是一定可以添加python3的路徑的。而不是在Run -> Edit configuration -> Python interpreter處添加。因為,如果你沒有在前者添加Python3, 後者是沒有這個選項的。當然,你在Project Interpreter處添加了python3之後,運作時可能還需要再改一下Edit configuration 裡面的python interpreter, 把其選為python3。

如何找到Project Interpreter,以下是官方文檔的介紹,但我的Mac路徑和官方文檔說的并不相同,而是在 File -> default settings 裡面。總之一定要找到Project Interpreter,才能正常添加。

https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html

https://www.jetbrains.com/help/pycharm/project-interpreter.html

後記,我最近發現,如果電腦裡安裝了多個python2.7或者python3.5, 3.6之類的,pycharm裡有2個地方需要設定:

1. File -> default settings,在project interpreter裡add locals,把你要用的這個python路徑加進來。

(如果找不到add locals,參考這篇文章:https://blog.csdn.net/codechelle/article/details/81203885)

2. Run -> Edit configuration -> Python interpreter 把interpreter改為你新添加的這個路徑。

其實還有一種方法,就是在打開pycharm的時候,不要選擇左邊一列原有的project,而是選“open”,打開你想用的這個python,比如在conda裡面,就直接把這個路徑打開。這樣pycharm的環境就會自動讀取你open的這個python。這時,你再在pycharm裡打開你要跑的檔案,應該就不需要重新配置了(當然,如果還需要重新配置,就用上述1、2重新配置下即可)。

繼續閱讀