I see in this article: making and automatic python installer that you can use:
subprocess.run('pip install module_name')
or
subprocess.run('pip install -r requirements.txt')
in this format to install modules either individually or form a file. But when i run this command I get this error:
FileNotFoundError: [Errno 2] No such file or directory:
is there a way to run this like that without having to do this:
subprocess.run(['pip', 'install', 'module_name'])
CodePudding user response:
To make it work on Linux I used the shell=True
parameter. On Windows, it worked perfectly, without it.
subprocess.run("python -m pip install -r requirements.txt", shell=True)
Found the answer here.
CodePudding user response:
I suggest you stick to subprocess.run(['pip', 'install', '-r', 'requirements.txt'])
. To quote the subprocess docs.
Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names).
Avoiding the use of shell=True
will save you a lot of trouble if you ever want to run the script on a different system. In general, though, I recommend avoiding reliance on a shell. That is, after all, why you are using Python and not, say, Bash.