I am trying to run python using Jupyter-lab locally.
I installed PyTorch on my Mac using brew. However pip doesn't see it and so does python
I installed PyTorch using pipx
python inside Jupyter doesn't see torch and neither does python from the command line
In Jupyter I see this -
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 # First, import PyTorch
----> 2 import torch
ModuleNotFoundError: No module named 'torch'
From the command line I see this --
>>> import torch
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
I am trying to run python using Jupyter-lab locally.
I installed PyTorch on my Mac using brew. However pip doesn't see it and so does python
I installed PyTorch using pipx
python inside Jupyter doesn't see torch and neither does python from the command line
In Jupyter I see this -
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 # First, import PyTorch
----> 2 import torch
ModuleNotFoundError: No module named 'torch'
From the command line I see this --
>>> import torch
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
Share
Improve this question
asked Feb 5 at 18:57
yyyyyyyyyy
611 silver badge2 bronze badges
3
|
1 Answer
Reset to default 0Because you are not using the environment, first activate the environment then open jupyter lab and then verify pytorch
For M1/M2 Macs, use the Apple Silicon version of PyTorch
Install Jupyter within the same virtual environment
pip install jupyterlab
Kernel Configuration
Install ipykernel to make the virtual environment available in Jupyter bash
pip install ipykernel python -m ipykernel install --user --name=pytorch_env
Always activate your virtual environment before launching Jupyter Lab to ensure correct package visibility.
pipx
installs into a separate virtual env; you must usepython
from that virtual env. Found in stackoverflow.com/search?q=%5Bpipx%5D+ModuleNotFoundError – phd Commented Feb 5 at 19:03