[英]I'm doing the cryptopals challenge 5. I'm getting a syntax error in line 5 when trying to run this script in kali linux
[英]I'm getting an error “module not found ” when I'm trying to execute shell commands through a python script
执行以下语句时
out1 = subprocess.run("module load python",shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
生成此错误。
/bin/sh:模块:命令未找到。
我想使用 python 脚本执行 shell 命令,上面的语句不起作用,但是当我在 shell 上执行相同的语句时,它工作正常并且没有生成错误。
module
不是外部命令,而是 function 以使用的 shell/脚本语言定义。 因此,要在 Python 脚本中启用module
命令,您需要使用以下代码对其进行初始化:
import os
exec(open('/usr/share/Modules/init/python.py').read())
将/usr/share/Modules/init
替换为您机器上安装python.py
脚本(来自 environment-modules 软件)的位置。
初始化后,您可以从脚本中调用module
function:
module('load', 'modulefile')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.