user6223604
user6223604

Reputation:

How to run upgrade pip version with command line

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

Answers (2)

Herbs
Herbs

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

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

Related Questions