Reputation:
I want to upgrade my pip version with a python script.
I need to run cmd as administrator and after run the command as below :
python -m pip install --upgrade --force-reinstall pip
How to do that please ?
Upvotes: 0
Views: 767
Reputation: 180
You can use os.system
to do this
import os
os.system('cmd /k "python -m pip install --upgrade --force-reinstall pip"')
/k
lets the command prompt remain after the command and can be replaced with /c
to kill the command prompt afterwards.
Upvotes: 1
Reputation: 8001
You can easily run any command with subprocess, this has the advantage that you get an exception if the command fails.
import subprocess
subprocess.check_call(["python", "-m", "pip", "install", "--upgrade", "pip"])
Or you can use os.system()
:
import os
os.system("python -m pip install --upgrade pip")
Upvotes: 3