Skip to content Skip to sidebar Skip to footer

How To Automatically Update Pyserial To LatesT?

I have the following code to raise an exception when pyserial version is less than 2.7,how do I programatically run pip install pyserial --upgrade to automatically update to latest

Solution 1:

use os.system('python -m pip install pyserial --upgrade') or use subprocess

Then once the installation is complete, check using python -m pip list command. This will work even if pip is not in the path.

import os
import subprocess

a = os.system('python -m pip install pyserial --upgrade')
if a == 0:
    d = subprocess.Popen('python -m pip list', stdout = subprocess.PIPE).communicate()
    if 'pyserial' in d[0]:
        print 'success'

Post a Comment for "How To Automatically Update Pyserial To LatesT?"