Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install npm package from python script?

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
nodejs error

like image 349
Vladimir Starkov Avatar asked Feb 04 '13 05:02

Vladimir Starkov


People also ask

Can npm install Python packages?

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.

What is npm install equivalent in Python?

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.


1 Answers

set the shell argument to True

subprocess.Popen(["node", "npm", "install", "open"], shell=True)
like image 186
Evan Siroky Avatar answered Sep 28 '22 04:09

Evan Siroky