I'd like to upgrade python version to 3.x for my Django project.
It's currently using python-2.7.
I failed to find a step by step guide on this.
Not sure how hard this is going to be...
I'd like to upgrade python version to 3.x for my Django project.
It's currently using python-2.7.
I failed to find a step by step guide on this.
Not sure how hard this is going to be...
This is a community wiki post. Feel free to add to this post in case you find something missing.
You will need to change Python path from Python27 to Python34 (or whatever version of Python you're using).
This is necessary because whenever you'll do django-admin.py startproject mysite
, command prompt will access only that script which is in your Path
.
For editing Path
variable: How to add Python path in windows 7?
lib2to3
lib2to3
will take care of most of the things which need to be rewritten for Python3.
class MyModel(...):
...
def __unicode__(self):
...
above code will be changed to:
class MyModel(...):
...
def __str__(self):
...
NOTE: lib2to3
will only change keywords etc. You'll need to change which modules you're using manually. For example, you'll have to change import StringIO
to import io
manually.
In case you want to do everything manually, here's a checklist for you:
__unicode__
with __str__
Change print
statement to print()
function
I don't think anybody uses print
in Django. But if you are, do change it.
Replace StringIO
and cStringIO
with io
StringIO.StringIO
becomes io.StringIO
. There is no cStringIO
in Python3.