I need to install pip package from Python because the people who have to install the package cannot use command line (please don't ask). I used answer from here and it did not work. In fact this installation requires stdout and stderr to be connected to something so I get an error number 2.
            Asked
            
        
        
            Active
            
        
            Viewed 30 times
        
    0
            
            
        - 
                    Could you write a bash file to just run all the pip install commands on the computer instead of having them run them directly from the command line themselves? – zypherman Jan 07 '21 at 18:19
- 
                    No because it is for people under Windows and I do not know where Python is installed. I could use the default installation directory (something like %USERPROFILE%/AppData/Local/Programs/Python/Python39) but they could have an older python installation. And the problem is that python is sometimes not in PATH. I found the answer below more generic. – user14959355 Jan 08 '21 at 09:19
1 Answers
0
            
            
        Running through the subprocess doc, I found the correct answer :
import subprocess,sys
subprocess.run([sys.executable, '-m', 'pip', 'install', package],stderr=subprocess.STDOUT,stdout=subprocess.PIPE,check=True)
Moreover, as a bonus, what was print on stdout and stderr is displayed.
 
    
    
        user14959355
        
- 96
- 2