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.py
Traceback (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_child
WindowsError: [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
npm allows installing packages globally or local to a project. In pip , all packages are installed globally. To separate the local dependencies from system-wide packages, a virtual environment is created which contains all the dependencies local to the project and even a local Python distribution.
Python uses pip for a package manager. The pip install command has a -r <file> option to install packages from the specified requirements file. Save this answer.
set the shell
argument to True
subprocess.Popen(["node", "npm", "install", "open"], shell=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With