抱歉,Google 和 DuckDuckGo 今天不是我的朋友(主要问题 — 我的小型实用程序需要自动本地安装包,因为全局包在 Windows 中不起作用.PS.我不得不问这个问题,因为我正在尝试为 Sublime Text 2 开发一个插件.这是 Sublime python 控制台中的错误:重新加载插件...\stsync.py回溯(最近一次调用最后一次):文件.\sublime_plugin.py",第 103 行,在 create_application_commands 中cmds.append(class_())文件.\stsync.py",第 16 行,在 __init__ 中文件.\subprocess.py",第 633 行,在 __init__ 中文件.\subprocess.py",第 842 行,在 _execute_child 中Windows 错误:[错误 2]第 16 行:subprocess.Popen(["node", "npm", "install", "open"])如果我将第 16 行更改为 subprocess.Popen(["node", "npm", "install", "open"])然后python脚本将成功调用nodejs终端,但随后将失败并显示错误:找不到 npm 模块 解决方案 将 shell 参数设置为 Truesubprocess.Popen(["node", "npm", "install", "open"], shell=True)How to install npm package from a python script?When I use subprocess.Popen(["node", "app.js"]) it is OK.When I use subprocess.Popen(["npm", "install", "open"]) it is throwing an error.Sorry, but Google and DuckDuckGo are not my friends today(The main problem — automatic local installation required packages for my small utility because global packages are not working in windows.PS. I have to ask this question because I’m trying to develop a plugin for Sublime Text 2.This is the error in Sublime python console:Reloading plugin …\stsync.pyTraceback (most recent call last): File ".\sublime_plugin.py", line 103, in create_application_commands cmds.append(class_()) File ".\stsync.py", line 16, in __init__ File ".\subprocess.py", line 633, in __init__ File ".\subprocess.py", line 842, in _execute_childWindowsError: [Error 2]line 16: subprocess.Popen(["node", "npm", "install", "open"])If I change line 16 to subprocess.Popen(["node", "npm", "install", "open"])then the python script will successfully invoke the nodejs terminal, but then it will fail with error:cannot find npm module 解决方案 set the shell argument to Truesubprocess.Popen(["node", "npm", "install", "open"], shell=True) 这篇关于如何从python脚本安装npm包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-06 04:26