Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
949 views
in Technique[技术] by (71.8m points)

visual studio code - VSCode Python version defaults to 2.7 in the integrated terminal no matter what I do

I'm running VSCode 1.36.0 on MacOS Mojave 10.14.6.

When I use the integrated terminal in VSCode and run Python it always runs Python 2.7 from /usr/bin/python on MacOS instead of the default anaconda Python. If I do the same in the system terminal everything is fine.

I've looked at the answers in these two related questions:

Why Is macOS Visual Studio Code Using Wrong Python Interpreter?

How can I change python version in Visual Studio Code?

I'm not running the code-runner extension. I've updated the python.pythonPath setting to point to Anaconda Python and yet no matter what I do, which python in the integrated terminal returns /usr/bin/python. Selecting a different conda environment with conda activate myenv doesn't do anything either.

Haven't experienced this issue before.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Get the shell path of your default terminal by executing echo $SHELL this should output something like /bin/bash

now check if the VSCode integrated Terminal points to the same shell and if not, set the integrated shell of VSCode to the one of your terminal.

Edit (to provide the full solution):

vsCode runs every new shell as login shell so if you set the Anaconda Path in .bashrc it will not be set in the integrated shell. If this is the case, you can set "terminal.integrated.shellArgs.osx": [] to force vsCode to run a non Login shell and load .bashrc


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...