PyQt from py27 to py38

RoadrunnerWMC roadrunnerwmc at
Tue Oct 26 17:12:29 BST 2021

(Just adding this to the mailing list, if you don't mind)

---------- Forwarded message ---------
From: Nicola Raffo <nicola.raffo at>
Date: Tue, Oct 26, 2021 at 11:15 AM
Subject: Re: PyQt from py27 to py38
To: RoadrunnerWMC <roadrunnerwmc at>

Similar scenario here, I have to deal with some data stored with pickled
PyQt4 objects. The pickletools method can be useful to "read" the pickled
data, but I need a conversion from PyQt4 to PyQt5 data in order to be able
to load the data in Python 3.8 and whitout a proper method to do it I can't
depickle data in Python 3.8.

Another idea could be to use the previous version of the code which still
uses python 2.7 and to store them in another format, but this could take a
long time.

What I need is a tool that allows me to automatically read and open these
data in Python 3.8
*From:* RoadrunnerWMC <roadrunnerwmc at>
*Sent:* 26 October 2021 17:06
*To:* Florian Bruhin <me at>
*Cc:* pyqt at <pyqt at>
*Subject:* Re: PyQt from py27 to py38

The pickletools method is at least doable for relatively simple pickles --
I have an application that does exactly that because another developer made
the less-than-wise decision to store pickled PyQt4 objects in user data
files a long time ago, and now I have to support reading them forever. The
main downside is that you have to make a lot of assumptions about the
structure of the pickle data, ones which technically don't *need* to always
be true, but *should* nevertheless be safe if your users are all using
CPython and not manually messing with the generated pickle data for some

There is another option, too, which is to make a minimal fake "PyQt4"
interface (just a few nearly-empty class stubs) and have pickle load using
that. I chose the pickletools method because of the additional security
benefits of avoiding using pickle.loads() on untrusted user data files.

On Tue, Oct 26, 2021 at 8:58 AM Florian Bruhin <me at> wrote:

On Tue, Oct 26, 2021 at 11:47:40AM +0200, Florian Bruhin wrote:
> The harder way is to somehow coerce pickle into giving you the "raw"
> data without the PyQt object involved...

I just learned there's 'pickletools' in the stdlib:

Using that, you could inspect the pickle manually and pick the data out
of it somehow. Given how pickles are structured, not exactly
straightfoward either, though.


            me at |
       GPG: 916E B0C8 FD55 A072 |
             I love long mails! |


*Nicola Raffo*

Senior Product Development Specialist

RuleX <>

+39 010 8050 190

PLEASE NOTE: This e-mail and any attachments may be confidential or
privileged and is intended solely for the addressee(s). Do not share or use
without Rulex's approval. If received in error, please contact the sender
and delete the email and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the PyQt mailing list