pythonjupyter-notebookvscode-extensionspython-venvvscodium

vscode (vscodium) - Python cannot import packages from venv


I want to use Jupyter Notebook feature. My virtual environment can run an ipykernel without issues (on code as well).

When I try importing a package, it acts as if the package doesn't exist. e.g.

import numpy
>>> ModuleNotFoundError: No module named 'numpy' 

However when I run Python ~/.venv/bin/python or even /usr/bin/python, numpy can be imported just fine.
I can host my own Jupyter notebook server, i.e. jupyter notebook and things also run just fine. I can even view the results as expected but not run the cells from over there.

edit: I'll expand the problem with new findings:
Launching built-in terminal launches /bin/sh with .venv sourced, rather than any of the shells I have in my computer (/usr/bin/zsh and /usr/bin/bash).
It can only detect bash, but not zsh, I've checked with which. Running python from bash defaults to .venv/bin/python again without prompting anything, but trying to import numpy fails again. Running python on /bin/sh also results in the same thing. The only packages I can import are the ones that are a part of the standard library (such as sys).
As such, I am going to edit the question title to include anything Python-related.
edit (2): The VSCode docpage on terminal profiles suggests this issue could be a terminal profile related one. However, attempting to add a terminal profile and setting it as default proved to be problematic as the app rejects the profile outright and defaults to sh.
Adding an entry zsh is not allowed as it "exists" in entries (it doesn't) and attempting to add it with a different name for /usr/bin/zsh results with the profile not appearing in the list. Therefore this appears to be a bug. I'll be moving this discussion to the issues page, and keeping this post for reference.

I'm running the following:

My default interpreter is set to be my venv, e.g. ~/.venv/bin/python. My "Venv path" setting is set as ~/.venv


Solution

  • This appears to be an issue with the terminal configuration as suggested in issue, keeping this as an answer for anyone having the same problem.