使用mac安装Python的torch包出现ImportError错误

使用mac安装torch、torchvision出现ImportError错误

使用mac安装Pytorch出现错误,安装torch成功之后,import torch出现错误 from torch._C import * 、Reason: image not found

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/__init__.py", line 81, in <module>

    from torch._C import *

ImportError: dlopen(/Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/_C.so, 9): Library not loaded: @rpath/libc++.1.dylib

  Referenced from: /Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/_C.so

  Reason: image not found

对于该种情况,转载文章https://blog.csdn.net/qq_41024144/article/details/105742035

在命令行输入:(其中两条指令的路径均为出现错误的Referenced from的路径)

第一步:otool -L /Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/_C.so

正常输出为:

/Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/_C.so:

@rpath/libshm.dylib (compatibility version 0.0.0, current version 0.0.0)

@rpath/libtorch_python.dylib (compatibility version 0.0.0, current version 0.0.0)

@rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)

第二步:install_name_tool -change @rpath/libc++.1.dylib /usr/lib/libc++.1.dylib /Users/jiangchao10/Library/Python/2.7/lib/python/site-packages/torch/_C.so

无任何输出

再次导入即可正常import torch

倘若第一步出现如下错误

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

对于该种情况,转载文章https://www.cnblogs.com/aresxin/p/7903242.html

对于xcrun错误,命令行输入xcode-select --install指令即可

再按照指令指令执行即可

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值