title: Python OR-tools function does not work when called from within a Python package
body: <p>I am new to Google OR-tools, and I have managed to get one of the examples to work when called from a <code>Jupyter Notebook</code>. However, when I take this working code and package it into a function in a python module I begin to encounter a <code>RunTimeError</code>.</p>
  
  <p>I am using:</p>
  
  <ul>
  <li><strong>Python 3.6.5</strong></li>
  <li><strong>ortools 7.0.6546</strong></li>
  <li><strong>jupyter 4.4.0</strong></li>
  </ul>
  
  <p>It seems I am missing something to make OR-tools available in my python package. I have looked up a similar error and come across suggestions to update the <code>distance_callback</code> function. But the function I am using is the suggested version anyway. </p>
  
  <h3>Working Code in Jupyter notebook</h3>
  
  <pre><code>from ortools.constraint_solver import routing_enums_pb2
  from ortools.constraint_solver import pywrapcp
  
  def distance_callback(from_index, to_index):
      """Returns the distance between the two nodes."""
      # Convert from routing variable Index to distance matrix NodeIndex.
      from_node = manager.IndexToNode(from_index)
      to_node = manager.IndexToNode(to_index)
      return data['distance_matrix'][from_node][to_node]
  
  def get_solution(manager, routing, assignment):
      index = routing.Start(0)
      output = [manager.IndexToNode(index)]
      while not routing.IsEnd(index):
          previous_index = index
          index = assignment.Value(routing.NextVar(index))
          output.append(manager.IndexToNode(index))
  
      return np.array(output)
  
  # Create the routing index manager.
  manager = pywrapcp.RoutingIndexManager(
      len(data['distance_matrix']), data['num_vehicles'], data['depot']
  )
  
  # Create Routing Model.
  routing = pywrapcp.RoutingModel(manager)
  
  transit_callback_index = routing.RegisterTransitCallback(distance_callback)
  
  # Define cost of each arc.
  routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
  
  # Setting first solution heuristic.
  search_parameters = pywrapcp.DefaultRoutingSearchParameters()
  
  search_parameters.first_solution_strategy = (
      routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC
  )
  
  search_parameters.time_limit.seconds = 30
  
  # Solve the problem.
  assignment = routing.SolveWithParameters(search_parameters)
  
  x = get_solution(manager, routing, assignment)
  </code></pre>
  
  <h3>Function contained in python module</h3>
  
  <pre><code>def packaged_function(data):
      # Create the routing index manager.
      manager = pywrapcp.RoutingIndexManager(
          len(data['distance_matrix']), data['num_vehicles'], data['depot']
      )
  
      # Create Routing Model.
      routing = pywrapcp.RoutingModel(manager)
  
      transit_callback_index = routing.RegisterTransitCallback(distance_callback)
  
      # Define cost of each arc.
      routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
  
      # Setting first solution heuristic.
      search_parameters = pywrapcp.DefaultRoutingSearchParameters()
  
      search_parameters.first_solution_strategy = (
          routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC
      )
  
      search_parameters.time_limit.seconds = 30
  
      # Solve the problem.
      assignment = routing.SolveWithParameters(search_parameters)
  
      return (manager, routing, assignment)
  </code></pre>
  
  <h3>Calling function from Jupyter</h3>
  
  <pre><code>from package_name.router import packaged_function
  output = packaged_function(data)
  </code></pre>
  
  <p>When I perform the call this way I end up with some errors, namely:</p>
  
  <pre><code>RuntimeError                              Traceback (most recent call last)
  RuntimeError: SWIG std::function invocation failed.
  
  The above exception was the direct cause of the following exception:
  
  SystemError                               Traceback (most recent call last)
  /usr/local/lib/python3.6/site-packages/ortools/constraint_solver/pywrapcp.py in &lt;lambda&gt;(self, name, value)
     2135         __swig_setmethods__.update(getattr(_s, '__swig_setmethods__', {}))
  -&gt; 2136     __setattr__ = lambda self, name, value: _swig_setattr(self, Assignment, name, value)
     2137     __swig_getmethods__ = {}
  
  /usr/local/lib/python3.6/site-packages/ortools/constraint_solver/pywrapcp.py in _swig_setattr(self, class_type, name, value)
       70 def _swig_setattr(self, class_type, name, value):
  ---&gt; 71     return _swig_setattr_nondynamic(self, class_type, name, value, 0)
       72 
  
  /usr/local/lib/python3.6/site-packages/ortools/constraint_solver/pywrapcp.py in _swig_setattr_nondynamic(self, class_type, name, value, static)
       54     if (name == "this"):
  ---&gt; 55         if type(value).__name__ == 'SwigPyObject':
       56             self.__dict__[name] = value
  
  SystemError: &lt;class 'type'&gt; returned a result with an error set
  
  The above exception was the direct cause of the following exception:
  
  SystemError                               Traceback (most recent call last)
      233 
      234     # Solve the problem.
  --&gt; 235     assignment = routing.SolveWithParameters(search_parameters)
      236 
      237     return (manager, routing, assignment)
  
  /usr/local/lib/python3.6/site-packages/ortools/constraint_solver/pywrapcp.py in SolveWithParameters(self, search_parameters, solutions)
     3423 
     3424     def SolveWithParameters(self, search_parameters: 'operations_research::RoutingSearchParameters const &amp;', solutions: 'std::vector&lt; operations_research::Assignment const * &gt; *'=None) -&gt; "operations_research::Assignment const *":
  -&gt; 3425         return _pywrapcp.RoutingModel_SolveWithParameters(self, search_parameters, solutions)
     3426 
     3427     def SolveFromAssignmentWithParameters(self, assignment: 'Assignment', search_parameters: 'operations_research::RoutingSearchParameters const &amp;', solutions: 'std::vector&lt; operations_research::Assignment const * &gt; *'=None) -&gt; "operations_research::Assignment const *":
  
  SystemError: &lt;built-in function RoutingModel_SolveWithParameters&gt; returned a result with an error set
  </code></pre>