我正在尝试建立一个奇异容器,以便在基于CentOS 7的群集上运行Python脚本。容器在我的主机上按预期运行,我也用它来创建容器,但是在导入PyTorch后立即在群集上失败。
可以通过此最小定义文件的容器构建来重现该问题:
debug.def:
Bootstrap: arch
%runscript
exec /usr/bin/python3 -c 'import torch; print(torch.__version__)'
%post
#--------------------------------------------------------------------------
# Basic setup from
# https://github.com/sylabs/singularity/blob/master/examples/arch/Singularity
#--------------------------------------------------------------------------
# Set time zone. Use whatever you prefer instead of UTC.
ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
# Set the package mirror server(s). This is only for the output image's
# mirrorlist. `pacstrap' can only use your hosts's package mirrors.
echo 'Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist
pacman -Sy --noconfirm gawk sed grep
# Set locale. Use whatever you prefer instead of en_US.
echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen
locale-gen
echo 'LANG=en_US.UTF-8' > /etc/locale.conf
pacman -S --noconfirm python python-pytorch
pacman -S --noconfirm pacman-contrib
paccache -r -k0
它是用sudo singularity build debug.sif debug.def
构建的。容器和主机都在Arch Linux上运行。
在我的主机上执行容器输出PyTorch版本:
schellsn@host $ singularity run debug.sif
1.3.1
在群集上运行它会导致以下错误:
schellsn@cluster tmp$ singularity run debug.sif
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/site-packages/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: libQt5Core.so.5: cannot open shared object file: No such file or directory
我不明白为什么找不到该文件,因为它应该包含在容器中:
schellsn@cluster tmp$ singularity shell debug.sif
Singularity debug.sif:~/tmp> ls -l /usr/lib | grep libQt5Core
-rw-r--r-- 1 root root 1166 Nov 11 23:40 libQt5Core.prl
lrwxrwxrwx 1 root root 20 Nov 11 23:40 libQt5Core.so -> libQt5Core.so.5.13.2
lrwxrwxrwx 1 root root 20 Nov 11 23:40 libQt5Core.so.5 -> libQt5Core.so.5.13.2
lrwxrwxrwx 1 root root 20 Nov 11 23:40 libQt5Core.so.5.13 -> libQt5Core.so.5.13.2
-rwxr-xr-x 1 root root 5275240 Nov 11 23:40 libQt5Core.so.5.13.2
我假设导入时搜索中未包括相应的路径,并且由于某些环境设置正在泄漏到容器中,所以在我的主机上不会发生此问题。我也尝试使用Sylabs Remote Builder,但似乎无法构造Arch容器(在$ PATH中找不到pacstrap)。尝试在其中一个节点上构建容器会导致相同的问题。 Pacstrap和pacman不可用。
我尽全力,非常感谢您提供任何解释这种行为的提示!为什么找不到共享库,如何解决?
更新#1:
这里是LD_LIBRARY_PATH环境变量的内容(响应@tsnowlan)。
Arch Linux主机:
schellsn@host tmp$ echo $LD_LIBRARY_PATH
:/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/cuda/lib64
schellsn@host tmp$ singularity shell evpt_debug.sif
Singularity evpt_debug.sif: ~/tmp> echo $LD_LIBRARY_PATH
:/usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/cuda/lib64:/.singularity.d/libs
CentOS 7群集节点:
schellsn@cluster tmp$ echo $LD_LIBRARY_PATH
schellsn@cluster tmp$ singularity shell debug.sif
Singularity debug.sif:~/tmp> echo $LD_LIBRARY_PATH
/.singularity.d/libs
更新#2:
我确实设置了一个新的干净VM(也正在运行arch),该VM也在那里重新构建了容器。这个容器显示了同样的问题。它在我的主机上运行,但不在CentOS 7集群上运行。
作为解决方法,我现在从一个def文件构建容器,该文件使用带有Ubuntu 18.04映像的库引导代理而不是Arch引导代理。生成的容器在我的Arch Host和CentOS 7群集上运行。