- 按照官网的命令安装后,报错找不到版本.
pip3 install torch torchvision

ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch
是因为用的python 3.13.2版本过高,重新创建python3.10环境
3. 安装pytorch成功,但运行报错
~ » python
Python 3.10.18 (main, Jun 5 2025, 08:13:51) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/__init__.py", line 1477, in <module>
from .functional import * # noqa: F403
File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/functional.py", line 9, in <module>
import torch.nn.functional as F
File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/nn/__init__.py", line 1, in <module>
from .modules import * # noqa: F403
File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
from .transformer import TransformerEncoder, TransformerDecoder, \
File "/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),
/opt/miniconda3/envs/py310/lib/python3.10/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),
是因为numpy版本过高,需要安装时限制numpy版本
pip3 install torch torchvision torchaudio "numpy<2.0"
老版本Mac最高支持的pytorch版本是2.2.0,参见链接,这个版本的pytorch只支持numpy1.x版本
之前一直想下载pytorch 2.4.0,后来发现不支持


39

被折叠的 条评论
为什么被折叠?



