pytorch踩坑记录
在Archlinux中使用conda安装pytorch,并import torch时遇到如下问题:
libtorch_cpu.so: cannot enable executable stack as shared object requires: Invalid argument
这个是 libtorch_cpu.so(PyTorch 的底层 C++ 动态库)要求设置 可执行栈(executable stack),但当前系统安全策略不允许。
这在 Arch Linux 或基于 musl / Hardened kernel / SELinux 的系统上时有发生,
尤其是 PyTorch 的预编译包(conda/pip)和系统内核安全配置不完全匹配时。
可以使用以下方法解决:
patchelf --clear-execstack XX/torch/lib/libtorch_cpu.so