Search code examples
pythonvisual-studio-codepipjupyter-notebookkernel

After updating python version, old downloaded packages not working in vsc when using jupyter


I updated my python version to latest in my WSL and now when running the latest kernel version with Visual Studio Code jupyter extension it cannot regognize the packages I have downloaded from pip with the earlier version.

With the earlier version (3.8.10) when I run

import torch

all goes normal, but when using (3.11.0) It says:

No module named 'torch'

I tried to download the packages from pip again and it seems to work but do I really have to do it with every package I have used with the earlier version or can I in some way update the packages or something?


Solution

  • Good practice is to have virtual env for each python version, using Anaconda or pipenv. in your case you may change the python path to the new version in you .bashrc file

    export PYTHONPATH=${PYTHONPATH}:${HOME}/[path to new version]
    

    source .bashrc and you good to go you can now install packages to the new version