title: Unpickling python objects with a changed module path
body: <p>I'm trying to integrate a project <code>Project A</code> built by a colleague into another python project. Now this colleague has not used relative imports in his code but instead done</p>
  
  <pre><code>from packageA.moduleA import ClassA
  from packageA.moduleA import ClassB
  </code></pre>
  
  <p>and consequently pickled the classes with <code>cPickle</code>. For neatness I'd like to hide the package that his (<code>Project A</code>) built inside my project. This however changes the path of the classes defined in <code>packageA</code>. No problem, I'll just redefine the import using</p>
  
  <pre><code>from ..packageA.moduleA import ClassA
  from ..packageA.moduleA import ClassB
  </code></pre>
  
  <p>but now the un pickling the classes fails with the following message</p>
  
  <pre><code>    with open(fname) as infile: self.clzA = cPickle.load(infile)
  ImportError: No module named packageA.moduleA
  </code></pre>
  
  <p>So why doesn't <code>cPickle</code> apparently see the module defs. Do I need to add the root of <code>packageA</code> to system path? Is this the correct way to solve the problem?</p>
  
  <p>The <code>cPickled</code> file looks something like</p>
  
  <pre><code>ccopy_reg
  _reconstructor
  p1
  (cpackageA.moduleA
  ClassA
  p2
  c__builtin__
  object
  p3
  NtRp4
  </code></pre>
  
  <p>The old project hierarchy is of the sort</p>
  
  <pre><code>packageA/
      __init__.py
      moduleA.py
      moduleB.py
  packageB/
      __init__.py
      moduleC.py
      moduleD.py
  </code></pre>
  
  <p>I'd like to put all of that into a <code>WrapperPackage</code></p>
  
  <pre><code>MyPackage/
  .. __init__.py
  .. myModuleX.py
  .. myModuleY.py
  WrapperPackage/
  .. __init__.py
  .. packageA/
     .. __init__.py
     .. moduleA.py
     .. moduleB.py
  .. packageB/
     .. __init__.py
     .. moduleC.py
     .. moduleD.py
  </code></pre>