我试图使用一个简单的脚本,在使用 SLURM 和 sbatch 时导入库命名空间,但是,我无法做到这一点,因为它找不到库(即使 pip list 显示它已安装在我的环境中)。
我正在运行的脚本非常简单:
#!/bin/python
#SBATCH --job-name=Python
#import namespaces as ns
import os
#location it should be installed
path = '/home/username/envs/tensorflow/lib/python2.7/site-packages'
ls = os.listdir(path)
print(ls)
print('namespaces' in ls) #does exist
#when using sbatch these lines fail
import namespaces as ns
print ns
它只是显示了库的安装位置。当我在 SLURM(集群)的头节点上运行它时,python ns_test.py
它会正确打印:
(env)user/om/user/user/MEng/hbf_tensorflow_code/tf_experiments_scripts $ python ns_test.py
['README', 'my-tf-proj.egg-link', 'tensorflow-0.9.0.dist-info', 'wheel', 'Keras-1.0.6.dist-info', 'numpy-1.11.1-py2.7.egg-info', 'wheel-0.29.0.dist-info', 'easy-install.pth', 'PyYAML-3.11.dist-info', 'sklearn', 'easy_install.pyc', 'google', 'tensorflow', 'namespaces', 'scikit_learn-0.17.1-py2.7.egg-info', 'setuptools-24.0.0.dist-info', 'wheel-0.29.0-py2.7.egg-info', 'keras', 'Theano-0.8.2.dist-info', 'easy_install.py', 'six.pyc', 'yaml', 'protobuf-3.0.0b2-py2.7-nspkg.pth', 'numpy-1.11.1.dist-info', 'namespaces-1.0.0.dist-info', 'pip-8.1.2-py2.7.egg-info', 'setuptools', 'theano', 'six-1.10.0.dist-info', 'setuptools-23.0.0-py2.7.egg', 'pip', 'setuptools.pth', 'six.py', 'protobuf-3.0.0b2.dist-info', 'scipy-0.17.1-py2.7.egg-info', 'numpy', 'external', 'pkg_resources', 'scipy']
True
<module 'namespaces' from '/home/user/envs/tensorflow/lib/python2.7/site-packages/namespaces/__init__.pyc'>
当我srun python ns_test.py
再次打印上述内容时。但是,当我使用 sbatch 时,它会打印(到 slurm 日志)以下神秘的代码行:
['README', 'my-tf-proj.egg-link', 'tensorflow-0.9.0.dist-info', 'wheel', 'Keras-1.0.6.dist-info', 'numpy-1.11.1-py2.7.egg-info', 'wheel-0.29.0.dist-info', 'easy-install.pth', 'PyYAML-3.11.dist-info', 'sklearn', 'easy_install.pyc', 'google', 'tensorflow', 'namespaces', 'scikit_learn-0.17.1-py2.7.egg-info', 'setuptools-24.0.0.dist-info', 'wheel-0.29.0-py2.7.egg-info', 'keras', 'Theano-0.8.2.dist-info', 'easy_install.py', 'six.pyc', 'yaml', 'protobuf-3.0.0b2-py2.7-nspkg.pth', 'numpy-1.11.1.dist-info', 'namespaces-1.0.0.dist-info', 'pip-8.1.2-py2.7.egg-info', 'setuptools', 'theano', 'six-1.10.0.dist-info', 'setuptools-23.0.0-py2.7.egg', 'pip', 'setuptools.pth', 'six.py', 'protobuf-3.0.0b2.dist-info', 'scipy-0.17.1-py2.7.egg-info', 'numpy', 'external', 'pkg_resources', 'scipy']
True
Traceback (most recent call last):
file "/home/slurm/slurmd/job3210331/slurm_script", line 12, in <module>
import namespaces as ns
ImportError: No module named namespaces
这真的很神秘,因为它确实说图书馆在那里!但是,当我将 import 语句与 sbatch 一起使用时,它找不到它。为什么会这样?我该如何解决这个问题?