[PyQt] PyQt4 and Python 3.0

Daniel Miller daniel at keystonewood.com
Tue Oct 7 14:07:27 BST 2008


On Oct 7, 2008, at 6:10 AM, Phil Thompson wrote:

>> And we could have just as many Viper versions as we'd damn well  
>> please
>> within any given Python and Qt release timeframe -- we'd simply  
>> import
>> from Viper2, Viper3... rather than Viper.
>>
>> Thoughts?
>
> With 20/20 hindsight (starting 10 years ago) I should have done  
> something
> along these lines. I'm certainly not going to change the structure  
> of PyQt3
> at this stage.
>
> At the moment I'm considering two possibilities...
>
> from PyQt4 import QtCore2

Why would you want to do this?

> ...which has the disadvantage of the number of changes needed if  
> you use
> the QtCore2.QLabel() style (which I do), and...
>
> from PyQt4v2 import QtCore

Or this? Do you like to make developers needlessly change their code?  
These are simply gratuitous name changes. It would be much more  
logical to keep the package and module names as similar as possible  
between versions. The correct place to put the version is in a  
__version__ attribute of the top-level package (i.e. in __init__.py).  
Then if you really need to know the version inside your program, do  
this:

import PyQt
print PyQt.__version__ # --> PyQt 4.3.3

People will not normally have multiple versions of PyQt installed,  
and if they do, they will certainly not be using multiple versions in  
a single application. To solve the problem of having multiple  
versions of PyQt installed at once, use the established egg/ 
setuptools packaging scheme where the version can be "required"  
before import like so:

require("PyQt==4.3.*")

This statement needs to be executed once before importing PyQt. It  
adds the correct PyQt version to sys.path so all subsequent import  
statements get the correct version, regardless of what other versions  
happen to be installed on the system. For more info on how it works  
see "Automatic Discovery" <http://peak.telecommunity.com/DevCenter/ 
PythonEggs>

This is definitely the most sane way to go as it allows developers to  
upgrade without changing anything that does not change from one  
version of PyQt to the next. Of course, if there are compatibility- 
breaking changes they will need to be fixed, but those should be the  
only changes required. It should NOT be required to touch every  
single source file that imports PyQt just to change it to import  
PyQt4v2 or whatever crazy top-level-namespace-polluting name the PyQt  
dev's come up with next... The switch from PyQt3 to PyQt4 was bad  
enough, please don't make us go through that again.

> Maybe a third possibility...
>
> from PyQt4.v2 import QtCore

Please no, in the name of all sanity and stability...

~ Daniel



More information about the PyQt mailing list