0

When I select a virtual environment (created with mac default venv command) as my interpreter for a Python file in VS Code, it doesn't change the Python executable path and instead uses my base interpreter. This question is unlike Selecting python interpreter in VSCode because their problem was solved by selecting an interpreter; I have no issue doing this and have done this process successfully several times before—this problem sprung up a week ago for unknown reasons. I am using sys.executable to check which python version is being used.

I have tried changing VS Code settings and making new venvs but the issue keeps replicating. If I had to guess, the issue might stem from some Terminal startup file?

Python File vs. Jupyter Notebook:

In each case I select the same interpreter but running print(sys.executable) returns different interpreter paths:

Python File Setup where I select my 'Education of the Colorblind' venv but then the interpreter used as executable is my base conda one.

Jupyter Notebook Setup where I select the same venv and the interpreter used is the correct, corresponding one also named 'Education of the Colorblind.'

Additional info if you find it useful:

Typing in Terminal which python with the venv activated gives normal results:

(Education of the Colorblind) MacBook-Air-5:Education of the Colorblind JonathanG-B$ which python
/Users/JonathanG-B/Desktop/Projects/Education of the Colorblind/bin/python

Workspace configuration file:

{
    "security.workspace.trust.untrustedFiles": "open",
    "code-runner.saveFileBeforeRun": true,
    "screencastMode.keyboardOptions": {
        "showKeys": false,
        "showSingleEditorCursorMoves": false
    },
    "python.defaultInterpreterPath": "/Users/JonathanG-B/anaconda3/bin/python",
    "terminal.integrated.inheritEnv": false,
    "files.autoSave": "afterDelay",
    "git.openRepositoryInParentFolders": "always",
    "jupyter.widgetScriptSources": [
        "jsdelivr.com",
        "unpkg.com"
    ],
    "jupyter.askForKernelRestart": false
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.