3 Error: Cannot find module 'jsdom'

指定绝对路径

python在使用execjs执行js也可以指定node_modules路径,这样就不需要进行环境变量的添加了。

js_code = open("toutiao_signature.js", "r", encoding="utf-8").read()
ctx = execjs.compile(
    # npm root -g   查看全局 node_modules 的路径
    js_code, cwd=r"/usr/local/lib/node_modules"
)
posted @ 2024-03-04 18:28  淋哥  阅读(71)  评论(0编辑  收藏  举报