最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

pytorch - Python doesn't see torch - Stack Overflow

programmeradmin0浏览0评论

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
  • stackoverflow.com/a/78960171/7976758 pipx installs into a separate virtual env; you must use python from that virtual env. Found in stackoverflow.com/search?q=%5Bpipx%5D+ModuleNotFoundError – phd Commented Feb 5 at 19:03
  • How do I use that inside Jupyter? – yyyyy Commented Feb 5 at 19:13
  • Install everything including Jupyter into one virtual env and run python from that virtual env. – phd Commented Feb 5 at 20:37
Add a comment  | 

1 Answer 1

Reset to default 0

Because 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.

发布评论

评论列表(0)

  1. 暂无评论