[Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?

Albert-Jan Roskam fomcl at yahoo.com
Tue Apr 21 13:55:16 CEST 2015





----- Original Message -----
> From: Mark Lawrence <breamoreboy at yahoo.co.uk>
> To: tutor at python.org
> Cc: 
> Sent: Tuesday, April 21, 2015 1:31 PM
> Subject: Re: [Tutor] Is it possible to "backport" the datetime module of Python 3.3 to Python 3.2?
> 
> On 20/04/2015 21:05, Albert-Jan Roskam wrote:
> 
>>  Hi,
>> 
>>  My Raspberry Pi 2 comes with Python 3.2 (and 2.7). I run some code that 
> uses the datetime module but I get an error:
>> 
>>  "AttributeError: 'datetime.datetime' object has no attribute 
> 'timestamp'". On https://docs.python.org/3/whatsnew/3.3.html I see: 
> "New datetime.datetime.timestamp() method: Return POSIX timestamp 
> corresponding to thedatetime instance." Is upgrading Python 3.3 or higher 
> my only option, or is it somehow possible to use the newer version of the 
> datetime library for Python 3.2? I do not want to modify the source code of the 
> library that causes the error (pysolar).
>> 
>>  Thanks!
>> 
>> 
>>  Regards,
>> 
>>  Albert-Jan
>> 
>> 
> 
> Python is very strong in guaranteeing backward compatibility, so why not 
> copy the 3.3 pure Python code to your 3.2 setup and see what happens?



Hmmm, nice idea. Never thought about that. Well, last night (before I saw your reply) I decided to download & compile Python 3.4, because I was afraid that this error might be the tip of the iceberg. Luckily, compiling the code went surprisingly fast on that little computer! I had to do it twice, though, because I got an error about _ssl (maybe with ensurepip?). I fixed it using "sudo apt-get install libssl-dev", but isn't the following the Offical Way (tm) to do this? Are there any more errors lurking in my Python 3.4 now? *) How do I find out the URL of the entry?


pi at raspberrypi ~ $ sudo apt-get build-dep python3.4
Reading package lists... Done
Building dependency tree 
Reading state information... Done
E: You must put some 'source' URIs in your sources.list


*) Argh, while writing this I can confirm that this is still not a good installation:

pi at raspberrypi ~ $ python3.4 -c "import sqlite3" 
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'



Probably this will work, but I will *never* be able to remember all these packages, so an entry in sources.list will be much nicer:
https://github.com/yyuu/pyenv/wiki/Common-build-problems

Best wishes,
Albert-Jan


More information about the Tutor mailing list