Django-admin.py producing errors on my shared hosting environment

Go To StackoverFlow.com

2

I tried to install django on my shared hosting environment, which has SSH access.

I downloaded the newest version of Django using

svn export http://code.djangoproject.com/svn/django/trunk/django django

I can import Django in python shell without any error throwing.

But then I tried to start a new project using django-admin.py and it started throwing me a bunch of error, in which I tried to google for the past few hours. I still can't find it

Below is the actual error:

k4660061@server42222:~$ django-admin.py startproject klikevent
/u/k4660061/home/local/lib/python/site-packages/django/core/management/templates.py:155: Warning: 'with' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
  File "/u/k4660061/home/local/lib/python/site-packages/django/bin/django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 381, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/u/k4660061/home/local/lib/python/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/commands/startproject.py", line 2, in <module>
    from django.core.management.templates import TemplateCommand
  File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/templates.py", line 155
    with open(old_path, 'r') as template_file:
            ^
SyntaxError: invalid syntax
k4660061@server42222:~$ 

Thanks


UPDATE

After a good night sleep, I got it working! See answer by Bernie. I have to see the stacktrace over and over, but I just need to add the import statement to multiple file

the file are

django/utils/archive.py django/core/management/templates.py

and any file that throw the warning with_statement

Thanks @Bernie

2012-04-04 17:02
by Steven St
+1 to you for working out the issues on your own - bernie 2012-04-05 03:26


1

If the syntax error is related to the with statement, it could be that your prod server has an older version of Python than your dev server.

If your prod server is running version 2.5 or higher you can do this:

from __future__ import with_statement

Please note: any from __future__ imports must be the very first import.
Reference: http://docs.python.org/reference/simple_stmts.html#future

2012-04-04 17:05
by bernie
So i just add that import line to django-admin.py - Steven St 2012-04-04 17:06
depends on what version of Python the server is running... have a look at this SO question for some ideas on how to determine that: http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-scrip - bernie 2012-04-04 17:08
I tried to add that import line to the first line of django-admin.py. still throwing the same error

If i try to use python, to call the shell. It says python 2.5.2

import sys print sys.version 2.5.2 (r252:60911, Jan 24 2010, 14:53:14) [GCC 4.3.2] sys.version_info (2, 5, 2, 'final', 0)

Steven St 2012-04-04 17:11
interesting. it appears that my answer is thoroughly unhelpful. apologies for leading you on a wild-goose chase, and best of luc - bernie 2012-04-04 17:14
No problem, Thanks for the help. It's better than me trying alone : - Steven St 2012-04-04 17:17
I got it working. I am not careful with the code last night, since i'm agitated from resolving this error the whole day. It threw the same error but in other location. I've updated my question with the answer. Thanks a lot @bernie - Steven St 2012-04-05 00:58
Ads