[英]Configuring the PATH variable in VS Code
I am using Microsoft Visual Studio Code 1.30.2 on macOS Mojave 10.14.3. 我在macOS Mojave 10.14.3上使用Microsoft Visual Studio Code 1.30.2 In the settings of VS Code, I have required it to use the external
Terminal.app
application on macOS. 在VS Code的设置中,我要求它使用macOS上的外部
Terminal.app
应用程序。 I also have an Anaconda distribution of Python installed. 我还安装了Python的Anaconda发行版。
Note that the PATH variable here reads: 请注意,这里的PATH变量为:
~ » $PATH
bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/anaconda3/bin:/anaconda3/condabin: No such file or directory
The order above is different from what I get if I fire up the regular Terminal app and get the PATH. 上面的顺序与我启动常规终端应用程序并获取PATH时得到的顺序不同。
~ » $PATH
-bash: /anaconda3/bin:/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin: No such file or directory
What this effectively does is switch the versions of Python when I type in python
in the two cases. 这实际上是在两种情况下键入
python
时切换Python的版本。 In the regular terminal, I get Python 3 right away, whereas in VS Code, I am faced with Python 2. 在常规终端中,我会立即获得Python 3,而在VS Code中,我将面对Python 2。
How do I change the PATH in VS Code so that whenever I type the words python
, I am always given Python 3 instead of 2? 如何在VS Code中更改PATH,以便每当我输入
python
字词时,总是得到Python 3而不是2?
PS Please note that while editing Python code in VS Code, I can always select which interpreter I want to use, but that does not change the situation with the terminal underneath. PS请注意,在VS Code中编辑Python代码时,我始终可以选择要使用的解释器,但这不会改变下面的终端的情况。
It sounds like your Workspace setting python.pythonPath
is set explicitly to the /usr/bin
. 听起来您的工作区设置
python.pythonPath
被显式设置为/usr/bin
。 Set that to match your preferred $PATH and you should be good to go. 将其设置为与您首选的$ PATH相匹配,那么您应该一切顺利。
Go to Preferences
in VS Code, search for python.pythonPath
, switch to Workspace
, and set as desired. 在VS Code中转到
Preferences
”,搜索python.pythonPath
,切换到Workspace
,然后根据需要进行设置。
I had the same problem, and I have a workaround solution. 我遇到了同样的问题,并且有解决方法。
I just add one line export PATH="/Users/username/anaconda3/bin:$PATH"
into .bash_profile or .zshrc 我只添加一行
export PATH="/Users/username/anaconda3/bin:$PATH"
到.bash_profile或.zshrc中
The orifinal $PATH in vscode is /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
vscode中的原始$ PATH是
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
And then my $PATH in vscode become /Users/username/anaconda3/envs/py36/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
然后我在vscode中的$ PATH变成
/Users/username/anaconda3/envs/py36/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
Please give it a try. 请试一试。 I wish the workaround might help.
我希望该解决方法可能有所帮助。 Thanks :)
谢谢 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.