On my first post destroyer22719 commented:
Hi there! This worked for me, however may I ask how this one works while the other one doesn't? I believe it's important for me that subprocess works.
I would like to say, I never learned how to use subprocess, so I wouldn't know how it works or anything. But, with a little bit of looking around I think I found a solution.
I tested on the latest version of ubuntu as of a week ago (python 3.8.10) and on my windows 10 (python 3.9) and it fails on windows 10 but works on ubuntu.
Ubuntu Version:
import subprocess
from threading import Thread
def package():
subprocess.Popen(["npm install express"], shell=True)
Thread(target=package).start()
print("This text will print if the command is finished or not.")
This is the one that works on windows:
import subprocess
from threading import Thread
def package():
subprocess.Popen(["npm", "install", "express"], shell=True)
Thread(target=package).start()
print("This text will print if the command is finished or not.")
threading is imported because when you run the process it doesn't just stop, so I used Thread() to get around that.
Usage: npm <command> npm install install all the dependencies in your project npm install <foo> add the <foo> dependency to your projectyou get the picture