Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't import torch mac

I'm trying to import torch and I'm getting the next problem:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/__init__.py", line 66, in <module>
    import torch._dl as _dl_flags
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so: mach-o, but wrong architecture
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so: mach-o, but wrong architecture

someone knows how can I solve this? Thanks:)

like image 626
chengal Avatar asked Jun 15 '26 08:06

chengal


1 Answers

Try like that:

mkdir test_torch
cd test_torch
python3 -m venv .venv
source .venv/bin/activate
pip install torch torchvision
python3

>>> import torch

Works for me. MacOS 10.13.4, Python 3.6.4

Or like that:

mkdir test_torch
cd test_torch
virtualenv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install torch torchvision
python2

>>> import torch

Works for me. MacOS 10.13.4, Python 2.7.10

If you don't need to use torch then you can install only torchvision

pip install --no-deps torchvision
like image 163
Greg Eremeev Avatar answered Jun 16 '26 23:06

Greg Eremeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!