为什么python不导入我的库,即使它在使用带有SLURM的sbatch时它会显示其当前的文件系统?

时间:2016-08-28 04:06:41

标签: python python-2.7 slurm sbatch

我在使用SLURM和sbatch时尝试使用导入库namespaces的简单脚本但是,我无法执行此操作,因为它找不到库(即使pip列表显示已安装在我的环境中。)

我正在运行的脚本非常简单:

#!/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

它只显示了库的安装位置。当我使用python ns_test.py在SLURM(群集)的头节点上运行它时,它会正确打印:

(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

这真的很神秘,因为它确实说库存在那里!但是,当我使用带有sbatch的import语句时,它找不到它。为什么会这样?我怎么能解决这个问题?

0 个答案:

没有答案