0

I am using datetime.strptime() to get the month number from a month, written in full english. I want to use this in combination with some PySide Qt intetrface. However, the month recognition seems to break as soon as I start a QApplication.

Minimum working example (i'm printing the locale to show that it doesn't change):

import sys, datetime

from PySide.QtCore import *
from PySide.QtGui import *

import locale

print(locale.getlocale())
full_date = 'February'
print(datetime.datetime.strptime(full_date,'%B'))

Output:

('en_US', 'UTF-8')
1900-02-01 00:00:00

Now when I start a QApplication and do the same:

import sys, datetime

from PySide.QtCore import *
from PySide.QtGui import *

import locale

qt_app = QApplication(sys.argv)

print(locale.getlocale())
full_date = 'February'
print(datetime.datetime.strptime(full_date,'%B'))

Output:

('en_US', 'UTF-8')
Traceback (most recent call last):
  File "my_timedate.py", line 12, in <module>
    print(datetime.datetime.strptime(full_date,'%B'))
  File "/usr/lib/python3.5/_strptime.py", line 510, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.5/_strptime.py", line 343, in _strptime
    (data_string, format))
ValueError: time data 'February' does not match format '%B'

What is going on? Why does it stop working after starting the QApplication?

Arvest
  • 13
  • 1
  • 5
  • 1
    I can't reproduce this using pyside-1.2.4. Presumably, there was a bug in some earlier versions. As a further test, you could also try running the same code with pyqt. – ekhumoro Jul 11 '16 at 14:50
  • I have installed PyQt5 version 3.5, and it shows the exact same behavior (i.e. still not working). I couldn't try PySide-1.2.4 as I am on Python3.5, which is not supported by Pyside-1.2.4, and I haven't managed to install Python3.4, yet.. (edit: by not working, I mean it shows the exact same error message) – Arvest Jul 13 '16 at 02:38
  • If you get the same behaviour with pyqt, it suggests some kind of issue with Qt, then. What specific version are you using? – ekhumoro Jul 13 '16 at 04:32
  • I've installed python-3.4 in a virtual environment, with PySide-1.2.4, and I recieve the exact same error as soon as I try to load a QApplication. I have also tried Python-3.5.1+ with PySide-1.2.2 and PyQt-5.6, all the same error/behavior. 'qmake --version' gives me: "QMake version 2.01a || Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gn" – Arvest Jul 13 '16 at 17:21
  • i have switched to Qt version 5, according to https://harishnavnit.wordpress.com/2014/03/24/handling-multiple-versions-of-qt/, and when I type 'qmake --version' it indicates qmake version 3.0 and Qt version 5.5.1. I still get the same behavior. I am not sure though if this will force the PySide / PyQt5 module to use Qt5, or that I would need to recompile the modules for it to change? – Arvest Jul 13 '16 at 19:23
  • PySide currently has no support for Qt5, so it will always use Qt4. PyQt5 can be compiled against either Qt4 or Qt5. You can check which one it is with: `python -c 'from PyQt5 import QtCore; print(QtCore.QT_VERSION_STR)'`. But I'm doubtful whether switching versions of any of the various components is going to fix the problem. It's beginning to seem more likely that this issue is specific to the setup on your system. But at the moment, I don't have any ideas about how to debug it any further. – ekhumoro Jul 13 '16 at 20:27
  • thanks for your help. I'm programming a quick month lookup routine myself now, let's see if somebody else can point me in the right direction. – Arvest Jul 13 '16 at 22:06

0 Answers0