della wrote: > Hi all, > > I've got some pickled files representing graphs (using networkx, > http://networkx.lanl.gov if you're interested) that were produced > using version 0.36 of the library. > > Now, they have released a new version of the library which is > incompatible with respect to pickled files, so what I'd like to do is > to write a script that loads the two versions of the library at once, > unpickles with the old one, creates a new object with the new version > and re-pickles it with the new version. > > So, I installed the two versions of the package using easy_install -m, > but it looks like I can't import the two versions at once: > >>>> from pkg_resources import require >>>> require('networkx==0.36') > [networkx 0.36 (/usr/lib/python2.5/site-packages/networkx-0.36- > py2.5.egg)] >>>> import networkx as nx_old >>>> require('networkx==1.0') > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 626, > in require > needed = self.resolve(parse_requirements(requirements)) > File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 528, > in resolve > raise VersionConflict(dist,req) # XXX put more info here > pkg_resources.VersionConflict: (networkx 0.36 (/usr/lib/python2.5/site- > packages/networkx-0.36-py2.5.egg), Requirement.parse('networkx==1.0')) > > Any ideas?
You can't do that. How should python distinguish between the two modules with the same name? What you can do is - import the old package - unpickle - convert to some neutral exchange format, simple dicts, lists, tuples - pickle that - import the new package - unpickle the exchange data - stuff it into the new classes Depending on who's got control for what, you might consider overloading the pickle protocol to allow for this more automatic in the future. This whole ruckus is BTW one of the reasons I moved away from ZODB. Diez -- http://mail.python.org/mailman/listinfo/python-list