Python 3 port - now available on GitHub

255 views
Skip to first unread message

Vinay Sajip

unread,
May 25, 2012, 5:51:54 AM5/25/12
to Django developers
The single codebase port of Django to Python 3 is now available on
GitHub [1]. Recent core changes have been merged, and the test results
are available at [2].

Summary:

2.7.2: Ran 4734 tests in 540.793s - OK (skipped=112, expected
failures=3)
3.2.2: Ran 4688 tests in 524.807s - OK (skipped=120, expected
failures=2, unexpected successes=1)

Recent tests only cover the SQLite backend and were run on Linux. Help
with testing other DB backends (and the GIS functionality) would be
much appreciated!

Regards,

Vinay Sajip

[1] https://github.com/vsajip/django/tree/django3
[2] https://gist.github.com/1373553

Anssi Kääriäinen

unread,
May 26, 2012, 1:16:00 AM5/26/12
to Django developers
Both Oracle and MySQL fail to run because of this error (on both 2.7
and 3.2):
File "/home/akaariai/Programming/django/tests/django/db/backends/
mysql/compiler.py", line 2, in <module>
from django.utils.itercompat import izip_longest
ImportError: cannot import name izip_longest

I get the following error when running the tests on any database on my
setup (Ubuntu 12.04, Python 3.2):
Traceback (most recent call last):
File "/home/akaariai/Programming/django/tests/regressiontests/
test_runner/tests.py", line 197, in
test_option_name_and_value_separated
self.assertNoOutput(err)
File "/home/akaariai/Programming/django/tests/regressiontests/
admin_scripts/tests.py", line 164, in assertNoOutput
self.assertEqual(len(stream), 0, "Stream should be empty: actually
contains '%s'" % stream)
AssertionError: 335 != 0 : Stream should be empty: actually contains
'b'\'import warnings\' failed; traceback:\nTraceback (most recent call
last):\n File "/home/akaariai/Programming/python3/lib/python3.2/
warnings.py", line 6, in <module>\n import linecache\n File "/home/
akaariai/Programming/python3/lib/python3.2/linecache.py", line 10, in
<module>\n import tokenize\nImportError: No module named tokenize
\n''

I used this to install my setup:
# sudo apt-get install python3 python3-dev virtualenv
# virtualenv -p python3 --distribute python3
# source python3/bin/activate
# pip install psycopg2
# run tests...

Am I missing some dependency?

PostgreSQL seems fine on 2.7 for the reduced test set ran
(introspection transactions inspectdb fixtures queries extra_regress
prefetch_related test_runner aggregation_regress). On 3.2 I get this
additional error:
Traceback (most recent call last):
File "/home/akaariai/Programming/django/tests/django/test/utils.py",
line 203, in inner
return test_func(*args, **kwargs)
File "/home/akaariai/Programming/django/tests/modeltests/
prefetch_related/tests.py", line 378, in test_child_link_prefetch
self.assertIn('authorwithage', connection.queries[-1]
['sql'].lower())
File "/usr/lib/python3.2/unittest/case.py", line 889, in assertIn
if member not in container:
TypeError: Type str doesn't support the buffer API

I do not have any GIS installations available on this machine.

- Anssi

Vinay Sajip

unread,
May 26, 2012, 6:31:20 AM5/26/12
to Django developers
Anssi,

Thanks very much for the feedback.

> Both Oracle and MySQL fail to run because of this error (on both 2.7
> and 3.2):
>   File "/home/akaariai/Programming/django/tests/django/db/backends/
> mysql/compiler.py", line 2, in <module>
>     from django.utils.itercompat import izip_longest
> ImportError: cannot import name izip_longest

I will investigate this.
There are problems with some virtualenv versions, see this open
virtualenv issue:

https://github.com/pypa/virtualenv/issues/194

The problem with importing tokenize.py in your traceback implies you
might be running into this issue.

> PostgreSQL seems fine on 2.7 for the reduced test set ran
> (introspection transactions inspectdb fixtures queries extra_regress
> prefetch_related test_runner aggregation_regress). On 3.2 I get this
> additional error:
> Traceback (most recent call last):
>   File "/home/akaariai/Programming/django/tests/django/test/utils.py",
> line 203, in inner
>     return test_func(*args, **kwargs)
>   File "/home/akaariai/Programming/django/tests/modeltests/
> prefetch_related/tests.py", line 378, in test_child_link_prefetch
>     self.assertIn('authorwithage', connection.queries[-1]
> ['sql'].lower())
>   File "/usr/lib/python3.2/unittest/case.py", line 889, in assertIn
>     if member not in container:
> TypeError: Type str doesn't support the buffer API

I'll investigate this too.

I've enabled the issue tracker in the port's GitHub repo [1]
- feel free to add any further findings there.

Kok Hoor Chew

unread,
May 27, 2012, 1:01:43 PM5/27/12
to django-d...@googlegroups.com
Hi Vinay / anyone interested in the Python 3 port,

I am a real newbie, so I seek forgiveness if what I did is stupid, but as I wanted to test out Vinay Sajip's django3 from git based on an existing project, I tried to install psycopg2 (Is this wise?)

I found following error when trying to browse to the admin site of my django app:

File ".../venv//lib/python3.2/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 8, in <module>
from django.db import utils
ImportError: cannot import name utils

And therefore I changed line 8 of the aforementioned code to:

from django.db.utils import *

It then works. Is this ok?

The pip freeze of my virtual env shows:

Django==1.5.dev20120527102728
distribute==0.6.24
psycopg2==2.4.5
wsgiref==0.1.2

Thanks.

Regards,
Kok Hoor
> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>

Vinay Sajip

unread,
May 28, 2012, 2:27:54 PM5/28/12
to Django developers
> I found following error when trying to browse to the admin site of my django app:
>
> File ".../venv//lib/python3.2/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 8, in <module>
> from django.db import utils
> ImportError: cannot import name utils

Not sure why it isn't working for you. The import seems to work for
me:

vinay@eta-oneiric64:~/projects/django3/tests$ PYTHONPATH=..
DJANGO_SETTINGS_MODULE=test_sqlite python3.2
Python 3.2.2 (default, Sep 5 2011, 21:17:14)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.db import utils
>>>

Regards,

Vinay Sajip

Anssi Kääriäinen

unread,
May 28, 2012, 3:24:43 PM5/28/12
to Django developers
On May 26, 1:31 pm, Vinay Sajip <vinay_sa...@yahoo.co.uk> wrote:
> There are problems with some virtualenv versions, see this open
> virtualenv issue:
>
> https://github.com/pypa/virtualenv/issues/194
>
> The problem with importing tokenize.py in your traceback implies you
> might be running into this issue.

Is there any workaround for this? I need to install psycopg2 and cx-
oracle under python 3 to run the tests, and virtualenv is the only way
I know how to do this. However, this issue is causing a lot of noise
in the results, making testing the py3-branch somewhat hard.

- Anssi

Ian Kelly

unread,
May 28, 2012, 5:48:41 PM5/28/12
to django-d...@googlegroups.com
On Sat, May 26, 2012 at 4:31 AM, Vinay Sajip <vinay...@yahoo.co.uk> wrote:
> Anssi,
>
> Thanks very much for the feedback.
>
>> Both Oracle and MySQL fail to run because of this error (on both 2.7
>> and 3.2):
>>   File "/home/akaariai/Programming/django/tests/django/db/backends/
>> mysql/compiler.py", line 2, in <module>
>>     from django.utils.itercompat import izip_longest
>> ImportError: cannot import name izip_longest
>
> I will investigate this.

The izip_longest definition was removed from itercompat in revision
b60b45a2a565 (which is fine, since it was only there for Python 2.5
compatibility), but it means that the places that imported it need to
be changed to import it directly from py3 instead.

Vinay Sajip

unread,
May 28, 2012, 5:51:13 PM5/28/12
to Django developers

On May 28, 8:24 pm, Anssi Kääriäinen <anssi.kaariai...@thl.fi> wrote:
> Is there any workaround for this? I need to install psycopg2 and cx-
> oracle under python 3 to run the tests, and virtualenv is the only way
> I know how to do this. However, this issue is causing a lot of noise
> in the results, making testing the py3-branch somewhat hard.

Just get a recent version of virtualenv.py and run that. For example,

https://raw.github.com/pypa/virtualenv/1.7.1.2/virtualenv.py

(I've not specifically tested this exact version, but IIRC I only had
the problem with my distro's version, which was a little out of date).

It's a self contained script, so just downloading it and running it
should allow you to create a working virtual environment.

Thanks for your input so far.

Regards,

Vinay Sajip

Vinay Sajip

unread,
May 28, 2012, 6:11:15 PM5/28/12
to Django developers

> The izip_longest definition was removed from itercompat in revision
> b60b45a2a565 (which is fine, since it was only there for Python 2.5
> compatibility), but it means that the places that imported it need to
> be changed to import it directly from py3 instead.

Right, and I fixed that a couple of days ago. Anssi has kindly posted
feedback to the GitHub issue tracker on my repo, so I'm following up
there.

Regards,

Vinay Sajip
Reply all
Reply to author
Forward
0 new messages