centos上使用python执行js代码报错--Could not find an available JavaScript runtime.

在CentOS 7.2的ECS上运行Python代码时遇到JS执行错误,因未安装Node.js环境导致无法执行JS代码。解决方案为通过YUM安装EPel-release和Node.js,确保JS代码可以被正确执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题、

我这个是在centos7.2 版本的ecs上执行python代码报错:
报错代码:

Traceback (most recent call last):
  File "3_sub_demand_id_493_search_key.py", line 262, in <module>
    spider_315_search_key_sub_demand_id_532.run_spider_all_key(keyword)
  File "3_sub_demand_id_493_search_key.py", line 62, in run_spider_all_key
    self.get_key_page_data(page, key)
  File "3_sub_demand_id_493_search_key.py", line 88, in get_key_page_data
    get_code = self.get_list_code(data)
  File "3_sub_demand_id_493_search_key.py", line 55, in get_list_code
    ctx = execjs.compile(js_str1)
  File "/usr/local/lib/python3.6/site-packages/execjs/__init__.py", line 61, in compile
    return get().compile(source, cwd)
  File "/usr/local/lib/python3.6/site-packages/execjs/_runtimes.py", line 21, in get
    return get_from_environment() or _find_available_runtime()
  File "/usr/local/lib/python3.6/site-packages/execjs/_runtimes.py", line 49, in _find_available_runtime
    raise exceptions.RuntimeUnavailableError("Could not find an available JavaScript runtime.")
execjs._exceptions.RuntimeUnavailableError: Could not find an available JavaScript runtime.

解决方法:

这个是因为centos上没有安装nodejs环境,不能执行js代码:

yum install epel-release
yum install nodejs

在这里插入图片描述

然后再执行代码即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhaojiafu666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值