独立运行Nsight Systems报告Python脚本报WITH语法错误求助
独立运行Nsight Systems自带gpukernsum脚本的报错问题
我复制了一份Nsight Systems自带的gpukernsum报告脚本做调整,需要独立运行该脚本,执行命令为:
./gpukernsum.py report.sqlite
第一次运行报错:Python语法错误
首次运行直接失败,报错信息如下:
ERROR: Script 'gpukernsum.py' encountered an internal error. $ ./gpukernsum.py report.sqlite File "./gpukernsum.py", line 40 """ ^ SyntaxError: invalid syntax
我判断报错原因是f"""多行字符串"""是Python 3专属语法,原脚本默认调用Python 2运行,因此修改了脚本的hash-bang行:
- 将原行
#!/usr/bin/env python - 替换为
#!/usr/bin/env python3
第二次运行报错:依赖模块缺失
修改hash-bang后再次运行脚本,出现模块找不到的报错:
$ ./gpukernsum.py report.sqlite Traceback (most recent call last): File "/path/to/./gpukernsum.py", line 7, in <module> import nsysstats ModuleNotFoundError: No module named 'nsysstats'
针对该问题,我把Nsight Systems对应的Python依赖目录加入了Python模块搜索路径,执行命令如下:
export PYTHONPATH="$PYTHONPATH:/opt/nvidia/nsight-systems/2022.1.1/host-linux-x64/python/lib"
第三次运行报错:WITH附近语法错误
配置完路径后再次运行脚本,出现新的报错:
$ ./gpukernsum.py report.sqlite near "WITH": syntax error
我核对了报错对应位置的代码,相关片段如下:
and not a percentage of the application wall or CPU execution time. """ query_stub = """ WITH summary AS ( SELECT coalesce({NAME_COL_NAME}, demangledName) AS nameId,
报错提到的WITH属于SQL查询字符串字面量的内容,我目前无法判断该错误是Python解释器抛出还是SQLite抛出,排查陷入停滞。
当前环境信息
- Nsight Systems 版本:2022.1.1
- 操作系统:CentOS 7
- 除上述hash-bang行修改、PYTHONPATH环境变量配置外,未改动
gpukernsum.py的原始代码 - 系统默认
python3对应版本为Python 3.9.1
内容的提问来源于stack exchange,提问作者einpoklum
相关产品推荐
相关产品推荐

