Feb-17-2019, 08:55 PM
Do not use
Example i check for module/package,if it's in outdated list i upgrade it.
So i have many modules/package that i don't care about or want to update.
os.system()
it's deprecated and unsafe,use subprocess . Example i check for module/package,if it's in outdated list i upgrade it.
import subprocess out = subprocess.run(['pip', 'list', '--outdated'], capture_output=True) response = out.stdout.decode() module_name = 'click' if module_name in response: subprocess.run(['pip', 'install', module_name, '--upgrade']) else: print(f'No module with name <{module_name}> found')
Output:E:\div_code
λ python sub_2.py
Collecting click
Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
Installing collected packages: click
Found existing installation: click 6.7
Uninstalling click-6.7:
Successfully uninstalled click-6.7
Successfully installed click-7.0
I only use pip list
in a virtual envorioment,as OS is mess because i do test a lot often to help users install problem on forum.So i have many modules/package that i don't care about or want to update.