python-3.x - SLURM 工作。NameError:名称'python3'未定义
问题描述
一段时间以来,我一直在试图弄清楚如何在 slurm 上运行工作。
用户目录中的 Python 版本:
$ python -V
Python 2.7.5
$ python3 -V
Python 3.6.8
test.py 包括:
import pandas as pd
import numpy as np
true = pd.read_csv("testfile.csv")
print('Just Testing. End for now.')
传递给 SLURM 的 gpu.job:
#!/usr/bin/python3
#SBATCH --job-name=testjob # Job name
#SBATCH --output=job.%j.out # Name of output file (%j expands to jobId)
#SBATCH --cpus-per-task=4 # Schedule one core
#SBATCH --gres=gpu # Schedule a GPU
#SBATCH --time=71:59:59 # Run time (hh:mm:ss) - run for one hour max
#SBATCH --partition=red # Run on either the Red or Brown queue
#SBATCH --mail-type=END # Send an email when the job finishes
#SBATCH --export=ALL # All of the users environment will be loaded from callers environment
python3 /home/username/test/test.py
运行后sbatch gpu.job
,我得到:
回溯(最近一次通话最后):
文件“/var/spool/slurm/d/job402350/slurm_script”,第 13 行,在
python3 /home/用户名/test/test.py
NameError: name 'python3' is not defined ~
这些变化也没有帮助,并给出了同样的错误:
python3 test.py
/usr/bin/python3 test.py
/usr/bin/python3 /home/username/test/test.py
建议将不胜感激。
解决方案
您的提交脚本是一个 shell 脚本,而不是 Python 脚本。所以你的提交脚本的第一行应该是
#!/usr/bin/env bash
而不是
#!/usr/bin/python3
从技术上讲,您可以提交一个 Python 脚本的作业脚本,但是#SBATCH
指令直接在 Python 脚本中得到,这就是您提交的脚本:
#!/usr/bin/python3
#SBATCH --job-name=testjob # Job name
#SBATCH --output=job.%j.out # Name of output file (%j expands to jobId)
#SBATCH --cpus-per-task=4 # Schedule one core
#SBATCH --gres=gpu # Schedule a GPU
#SBATCH --time=71:59:59 # Run time (hh:mm:ss) - run for one hour max
#SBATCH --partition=red # Run on either the Red or Brown queue
#SBATCH --mail-type=END # Send an email when the job finishes
#SBATCH --export=ALL # All of the users environment will be loaded from callers environment
import pandas as pd
import numpy as np
true = pd.read_csv("testfile.csv")
print('Just Testing. End for now.')
然后你可以sbatch
直接使用这个 Python 脚本。但大多数情况下,最好使用 Bash 脚本来设置环境、更改目录、来回复制文件等,这在 Bash 中比在 Python 中更容易。
推荐阅读
- javascript - 基于浏览器时间的 CSS
- jmeter - 下载某些数据后如何在 Jmeter 中停止执行用户
- bash - 如何在保存命令的变量中传递命令参数?
- scala - 无法在本地创建表,需要获得 Hive 支持
- asp.net - Web.Config 大写到小写重定向 - 丢失 HTTPS 架构
- r - 将图例添加到分层 ggplot
- python - 输出数据时可用的 python 提示符
- node.js - 将 2 个不同的容器连接到同一个 mongoDB 容器
- html - 如何使下一个/后退按钮订单可访问
- r - 如何在 R 中更改 ggplot 和 ggplotly 中显示的 x 值