解决pyintaller 打包生成的exe文件,node运行js有cmd弹窗问题,解决node指定路径问题(其他电脑不需要安装node环境)
解决node运行js有cmd弹窗问题
需要改execjs源码,添加一个 shell=True
#点击 _external_runtime
from execjs._external_runtime import ExternalRuntime
#找到Popen
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=self._cwd, universal_newlines=True)
#添加
shell=True
解决node指定路径问题
filePath = os.getcwd()
try:
node_exe_path = filePath + "/node/node.exe"
print(filePath)
# 设置Node.js的路径
local_node_runtime = execjs.ExternalRuntime(
name="Node.js (V8) local",
command='',
encoding='UTF-8',
runner_source=_runner_sources.Node
)
# 这里是重点,需要强制性修改
local_node_runtime._binary_cache = [node_exe_path]
local_node_runtime._available = True
# 将刚创建好的 JavaScript 运行时 注册至 PyExecJS 中
execjs.register('local_node', local_node_runtime)
with open('bdms.js', "r", encoding="utf-8") as file:
js_code = file.read()
ctx = execjs.get('local_node').compile(js_code)
except Exception as e:
logging.error("不小心报错了:%s", e)