[PyQt] pytz and timezones....

Phil Thompson phil at riverbankcomputing.com
Tue Nov 24 15:17:47 GMT 2015


On 24 Nov 2015, at 2:55 p.m., John M. Hackett <john.hackett at icon-is.co.uk> wrote:
> 
> My App builds but a "UnknownTimeZoneError" is thrown by pytz/__init__.pyo when it is run.
> 
> I've put various logging lines and its looks to me as if the issue is where this file tries to confirm the existence of the zoneinfo file(s): for each tz in a hardcoded array it checks to see if it can open the file defined as:
> 
> filename = os.path.join(os.path.dirname(__file__),'zoneinfo', *name_parts)
> 
> This generates something like ":/pytz/zoneinfo/Europe/London".
> 
> Now the question is what does the ":" represent? The actual path to the pre-build file is, in this example, "$SYSROOT/resources/pytz/zoneinfo/Europe/London" which does exist.
> 
> So, when pyqtdeploy builds the App does the ":" in the filename above represent the "internal" root of the App so that when it tries to open this file it is looking within the App's own directory structure and not some "real" path?
> 
> If this is not the case and it is trying to open a file external to the app and within the general filesystem how can I get to read the zoneinfo which is, I assume, being embedded in the App as a resource?

The ":" tells Qt that the file is stored in a rcc generated file. QFile understands this, the regular Python open() function doesn't.

You have, I think, two choices. One is to distribute the zoneinfo files outside of the executable, in which case you will need to change pytz to locate them correctly (something based on sys.executable?).

The other choice is to change pytz to use QFile to read the zoneinfo files.

Phil


More information about the PyQt mailing list