To view the installed libraries on an environment I run this code within a Jupyter Python notebook cell :
%%bash
pip freeze
This works, but how to conditionally execute this code ?
This is my attempt :
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def f(x1):
if(x1 == True):
f2()
return x1
interact(f , x1 = False)
def f2():
%%bash
pip freeze
But evaluating the cell throws error :
File "<ipython-input-186-e8a8ec97ab2d>", line 15
pip freeze
^
SyntaxError: invalid syntax
To generate the checkbox I'm using ipywidgets : https://github.com/ipython/ipywidgets
Update :
Running pip freeze
within check_call
returns 0 results :
Running
%%bash
pip freeze
Returns installed libraries so 0 is not correct.
Is subprocess.check_call("pip freeze", shell=True)
correct ?
Update 2 :
This works :
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import subprocess
def f(View):
if(View == True):
f2()
interact(f , View = False)
def f2():
print(subprocess.check_output(['pip', 'freeze']))