ducati1212
ducati1212

Reputation: 201

VSCode terminal is using the wrong python version

I have a new mac with python 3 installed from homebrew and visual studio code. I am not a python person by default I tend to use java but wanted to try a project for fun.

Just my terminal in VSCode has a system install of python 3.8 version that I am not using I want to use my brew install version as shown in screen shots. if I do echo $path it shows correct, my mac terminal shows correct and my VSCode python plugin has the correct version showing. I have rebooted several times in case it was cached.

I want to use the brew version 3.9.7. My project is failing to load imports such as "import requests" I assume because of this. The import fail error is.

Import "requests" could not be resolved from sourcePylancereportMissingModuleSource

I have installed and uninstalled requests many times always through VSCode command line.

enter image description here

enter image description here

Upvotes: 2

Views: 7062

Answers (3)

Danieee
Danieee

Reputation: 1

Go into VS Code settings: Code->Preferences->Settings. Type the following in the search box:

terminal.integrated.inheritEnv": false

Uncheck the option box beside the setting "whether new shells should inherit their environment from VS Code..." to set it to False.

Restart VS code and try again, you should have the same version of python as on your standard terminal.

Upvotes: 0

user3661992
user3661992

Reputation: 491

Try putting the following in settings.json:

"terminal.integrated.env.osx": {
        "PATH": ""
}

Save the file, close any terminal window and restart VS Code.

You can read more here.

Upvotes: 1

Kottory
Kottory

Reputation: 11

Perhaps the values in $PATH of VS Code is in a different order than that of Terminal.app.

See https://github.com/microsoft/vscode/issues/70248 for more informations.

You can simply set "terminal.integrated.inheritEnv": false. This works well for me.

Upvotes: 1

Related Questions