VS Code找不到python 3解释器 [英] VS Code can't find python 3 interpreter

查看:834
本文介绍了VS Code找不到python 3解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次安装Python 3.7.2,并且正在使用VS Code python扩展.

I am installing Python 3.7.2 for the first time, and I'm using the VS Code python extension.

当我运行python -V时,我得到了Python 2.7.10这是不正确的!

When I run python -V I get Python 2.7.10 which is not correct!

当我在VS Code中选择usr/local/bin/python3解释器时,在运行脚本时出现此错误:

When I select the usr/local/bin/python3 interpreter in VS Code I get this error when running a script:

bash:/Users/erik/Work/Python/usr/local/bin/python3:没有这样的文件或目录

bash: /Users/erik/Work/Python/usr/local/bin/python3: No such file or directory

但是当我查看usr/local/bin时,我可以看到Python3在那里.我不确定VS Code为什么将工作目录粘贴到usr/local/bin前面?

But when I look in usr/local/bin I can see that Python3 is there. I'm not sure why VS Code pastes the work directory in front of usr/local/bin ?

我的第一个想法是Python3应该在PATH变量中,因此我运行了包含的Update Shell Profile命令,该命令给出了以下反馈:

My first thought was that Python3 should be in the PATH variable so I ran the included Update Shell Profile command, which gives this feedback:

This script will update your shell profile when 
the 'bin' directory of python is not early enough
of the PATH of your shell. 

All right, you're a python lover already

现在,在重新启动VS Code之后,我得到了一个用于选择解释器的新选项:

Now, after rebooting VS Code I get a new option for selecting an interpreter:

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

usr/local/bin中的Python有区别吗?选择它时,出现此错误:

Is that different from the Python in usr/local/bin ? When I select it, I get this error:

脚本isort安装在PATH之外的'/Users/erik/Library/Python/3.7/bin'中.

The script isort is installed in '/Users/erik/Library/Python/3.7/bin' which is not on PATH.

我也得到了这个与横向有关的错误:

I also get this sideways related error:

您正在使用pip版本18.1.您应该考虑通过"pip install --upgrade pip"命令进行升级.

You are using pip version 18.1. You should consider upgrading via the 'pip install --upgrade pip' command.

但是,按照这些说明进行操作时,我又遇到了另一个错误:

But, when following these instructions I get yet another error:

bash:pip:找不到命令

bash: pip: command not found

总而言之,此过程和官方文档似乎不够用户友好?显然,在编写一行代码之前,我需要在终端中深入研究Mac的系统文件.

All in all, this process and the official documentation seem less than user-friendly? Apparently I'm required to dig deep through my mac's system files in the terminal before even writing one line of code.

我在这里错过了必要的步骤吗?

Am I missing an essential step here?

推荐答案

好吧,如果您想更改整个系统的默认Python版本,则可能会破坏某些依赖于Python 2的应用程序.

Well, if you want to change your default Python version for the whole system, it might break some applications that are depending on Python 2.

您可以通过将以下行添加到~/.bash_profile中来为命令添加别名:

You can alias the commands by adding this line to your ~/.bash_profile:

$ alias python='python3'

python命令现在将引用python3.

如果要执行原始的Python(指的是python2),则可以转义别名(因此\python将在不触摸别名的情况下启动python2).

If you want to execute the original Python (which refers to python2), you can escape the alias (so \python will launch python2 without touching the alias).

顺便说一句

$ unlink /usr/local/bin/python
$ ln -s /usr/local/bin/python3.7 /usr/local/bin/python

也可能是您的解决方法.

could also be a workaround for you.

这篇关于VS Code找不到python 3解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆