Run this command in a Jupyter notebook cell: !which python
Compare the output with the Python environment where 'torch' is installed.
Run this command in a Jupyter notebook cell: !pip install torch
Or, if using 'conda': !conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
If you want Jupyter to use the Python environment where 'torch' is already installed:
Install the 'ipykernel' package in your Python environment: pip install ipykernel
Add your Python environment to Jupyter: python -m ipykernel install --user --name=myenv --display-name "Python (myenv)"
Replace 'myenv' with the name of your Python environment.
Restart Jupyter Lab and select the correct kernel:
Open Jupyter Lab. Go to the 'Kernel' menu > 'Change Kernel' > Select the kernel named "Python (myenv)". 4. Restart Jupyter Lab
After ensuring that 'torch' is installed in the correct environment or Jupyter is using the desired environment, restart Jupyter Lab and test again.