PyQt from py27 to py38

Nicola Raffo nicola.raffo at rulex.ai
Wed Oct 27 10:19:48 BST 2021


Hi Damien,

I have tried something similar in the past days but it seems not working to directly convert objects from PyQt4->PyQt5.

However, it has some good tips that I could partially use.

Thank you for you help.

Nicola
________________________________
From: Damien Elmes <pyqt at ankiweb.net>
Sent: 27 October 2021 09:55
Cc: pyqt <pyqt at riverbankcomputing.com>
Subject: Re: PyQt from py27 to py38

Here is an example of how we do it for PyQt5→PyQt6:

https://github.com/ankitects/anki/blob/036d04a7b1514fde0018280a79e98066275dae9c/qt/aqt/profiles.py#L159<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fankitects%2Fanki%2Fblob%2F036d04a7b1514fde0018280a79e98066275dae9c%2Fqt%2Faqt%2Fprofiles.py%23L159&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878857049%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=CruPvq4y86AOAUW%2BQQSdroPgWNRC2yJ6q%2FNQ6h%2FP6ws%3D&reserved=0>

You might be able to adapt it for PyQt4 as well. In our case we were incorrectly storing the pickled data back in the Python 2 days, so couldn't safely bring it into PyQt5.

On Wed, Oct 27, 2021 at 3:07 AM Tomas Sobota <tom at sobota.net<mailto:tom at sobota.net>> wrote:
A couple of ideas here:
https://stackoverflow.com/questions/54047757/unpickle-binary-file-to-text/54048296#54048296<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F54047757%2Funpickle-binary-file-to-text%2F54048296%2354048296&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878857049%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=hETVSCuk%2BbQ994nx30wq2Xoq2XfH%2FVBbfIEMPsB5e94%3D&reserved=0>
Maybe you could take it from there?
Tom

On Tue, Oct 26, 2021 at 6:12 PM RoadrunnerWMC <roadrunnerwmc at gmail.com<mailto:roadrunnerwmc at gmail.com>> wrote:
(Just adding this to the mailing list, if you don't mind)

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


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 gmail.com<mailto:roadrunnerwmc at gmail.com>>
Sent: 26 October 2021 17:06
To: Florian Bruhin <me at the-compiler.org<mailto:me at the-compiler.org>>
Cc: pyqt at riverbankcomputing.com<mailto:pyqt at riverbankcomputing.com> <pyqt at riverbankcomputing.com<mailto:pyqt at riverbankcomputing.com>>
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 reason.

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 the-compiler.org<mailto:me at the-compiler.org>> 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:
https://docs.python.org/3/library/pickletools.html<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.python.org%2F3%2Flibrary%2Fpickletools.html&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878867044%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=XBl32YTRlfQSlM2zI6c2qGqc%2FLfctm92RrxqJWusYeI%3D&reserved=0>

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.

Florian

--
            me at the-compiler.org<mailto:me at the-compiler.org> | https://www.qutebrowser.org<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.qutebrowser.org%2F&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878877034%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Z5Y3EddE%2Fd73B632%2B8GFwboO62ojuptRgOIYETQwTYc%3D&reserved=0>
       https://bruhin.software/<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbruhin.software%2F&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878877034%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=AWr4a40iUhdZnIUDJv1AZc95Cfb16TP3ABT0SjMNNT4%3D&reserved=0> | https://github.com/sponsors/The-Compiler/<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fsponsors%2FThe-Compiler%2F&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878887033%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=irlg32UwQ1qfLfECWBe1T%2FrL18517s62XJLppL48Gtk%3D&reserved=0>
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fthe-compiler.org%2Fpubkey.asc&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878887033%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lI5oMnsbTpxNj%2FkHcSCw4GqMDOe8CKfwHqZ02q2Pz%2F8%3D&reserved=0>
             I love long mails! | https://email.is-not-s.ms/<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Femail.is-not-s.ms%2F&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878897026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=NP9IOnKXjUYp5sfjOBeAWvcjiYq9oONcniW5frUJqvo%3D&reserved=0>

--

Nicola Raffo

Senior Product Development Specialist

RuleX<https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Frulex.ai%2F&data=04%7C01%7Cnicola.raffo%40rulex.ai%7C1f16bbca75e4467de4d508d9991f45ef%7Ccb4c9caf154d430fade0c36c8af22d19%7C0%7C0%7C637709181878897026%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=6R9KjNgLmAqfdQuV1pFWcjQ1Do%2Ft5f%2FkOovyt1MfhQ8%3D&reserved=0>

+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: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20211027/4954741c/attachment-0001.htm>


More information about the PyQt mailing list