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重新配置下即可)。

猜你喜欢

转载自blog.csdn.net/codechelle/article/details/77050957