pythonpandaswindows-subsystem-for-linuxvirtual-environmentpymupdf

VS Code Problem: "Import "pandas" could not be resolved from source"


I am running a virtual environment for my project in VS code, and installed pandas and PyMuPDF but I cannot fix the flagged problems below. Please note that I am using a WSL command terminal with a Windows OS.

I've looked at prior stackoverflow threads, but the suggestions have not been able to fix this issue. I made sure that my packages are installed properly (see screenshot). My installed panadas version is 2.2.3 and my python version is 3.12.3 in the virtual environment.

enter image description here

This leads me to believe that I do not have the correct Python interpreter selected, but when I browse my file system to select a different interpreter in the venv/bin folder, it's empty so I cannot select a python interpreter. However, when I run "ls venv/vin", it shows that there are several Python interpreters installed (see screenshot).

enter image description here

I tried manually adding a path to my settings.json file to the Python interpreter, but that did not work either.

I do not know what to do from this point. If someone could please help, that would be much appreciated!


Solution

  • The simplest way to solve this is to create a new virtual environment, VScode usually recognizes that a new venv has been created and allows you to switch to that new environment.

    in your vscode terminal, run rm -r {your env folder}, then python venv .venv (the name should be ".venv", sometimes it helps vscode recognize that this is a venv). You should receive a small modal at the bottom right of the screen for switching to the new environment. If you don't receive it, use source ./.venv/Scripts/Activate.

    If all of this doesn't work, try running wsl code . to open vscode using wsl. It's very much possible that vscode is looking for a windows venv and fails to find a linux venv.