There is no error when the code (ipynb) below is ran:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

# We'll also import a few standard python libraries
from matplotlib import pyplot
import numpy as np
import time

# These are the droids you are looking for.
from caffe2.python import core, workspace, brew
from caffe2.proto import caffe2_pb2
from caffe2.python.model_helper import ModelHelper

inp = np.random.randn(7, 3, 224, 224).astype(np.float32)

workspace.FeedBlob('X', inp)

True

model = ModelHelper()

conv1 = brew.conv(model, 'X', 'conv1', 3, 5, 3)

workspace.RunNetOnce(model.param_init_net)

True

workspace.CreateNet(model.net)

True

workspace.RunNet(model.net)

True

However, if I run the same code in py file:
from __future__ import absolute_import                                                                                  
from __future__ import division                                                                                         
from __future__ import print_function                                                                                   
from __future__ import unicode_literals                                                                                 
                                                                                                                        
# We'll also import a few standard python libraries                                                                     
from matplotlib import pyplot                                                                                           
import numpy as np                                                                                                      
import time                                                                                                             
                                                                                                                        
# These are the droids you are looking for.                                                                             
from caffe2.python import core, workspace, brew                                                                         
from caffe2.proto import caffe2_pb2                                                                                     
from caffe2.python.model_helper import ModelHelper                                                                      
                                                                                                                        
inp = np.random.randn(7, 3, 224, 224).astype(np.float32)                                                                
workspace.FeedBlob('X', inp)                                                                                            
model = ModelHelper()                                                                                                   
conv1 = brew.conv(model, 'X', 'conv1', 3, 5, 3)                                                                         
workspace.RunNetOnce(model.param_init_net)                                                                              
workspace.CreateNet(model.net)                                                                                          
workspace.RunNet(model.net)                                                                                             
print(model.net.Proto())                                                                                                
print(workspace.FetchBlob('conv1').shape, "Final")                                                                      


Error (while running in py file):

WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.

WARNING: Logging before InitGoogleLogging() is written to STDERR

W1126 14:07:14.579519 321242560 init.h:99] Caffe2 GlobalInit should be run before any other API calls.

W1126 14:07:14.579742 321242560 init.h:99] Caffe2 GlobalInit should be run before any other API calls.

I1126 14:07:14.579951 321242560 operator.cc:169] Engine CUDNN is not available for operator Conv.