Run custom Django management command over SSH - python

I have a Django application with a custom management command in one of the apps. If I log in over SSH I can run it without any problems with
python manage.py sitedir/mycommand
However, if I try to run the command as a oneliner from my local box like this:
ssh myserver python manage.py sitedir/mycommand
I get an ImportError like this:
Traceback (most recent call last):
File "mysite/manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named mysite.myapp.management.commands.mycommand
The real reason is that I want to run this admin command from a Fabric script but until I can get it to run via the ssh one-liner I guess it will be impossible. Is there something in the environment that differs when you run it via the ssh one-liner? The python path seems correct in both cases.

I think I have a clue what is going on. I don't know how to fix it yet.
To reproduce your scenario I wrote a small script.
#!/usr/bin/python
import sys, django
print django.VERSION
After which I executed it after logging in through SSH as well as remotely (ssh yourserver.com "python /home/me/script.py") and everything went fine.
Then I changed the script.
#!/usr/bin/python
import os
print os.environ['DJANGO_SETTINGS_MODULE']
This version worked when I logged in to the server but failed when I tried to execute it remotely.
Traceback (most recent call last):
File "/home/me/script.py", line 3, in <module>
print os.environ['DJANGO_SETTINGS_MODULE']
File "/usr/lib/python2.5/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'DJANGO_SETTINGS_MODULE'
Apparently the DJANGO_SETTINGS_MODULE environment variable is not set when you execute the command remotely over SSH. I suspect this may be what is going wrong in your case. You will need to figure out how to make sure that this variable is properly set before executing the script.
Perhaps you can explicitly set it: os.environ['DJANGO_SETTINGS_MODULE'] = 'foo'..
Try this:
ssh yourserver.com "python /home/me/script.py" -t
DJANGO_SETTINGS_MODULE=app.settings.custom

You may try mysite path to sys.path in manage.py? It could help - as I can see now python does not see mysite directory.
import sys
sys.path.append('mysite_directory')

This could be because the .profile file is not loaded. Try this instead (replace .profile with your shell profile):
ssh myserver '. ~/.profile; python manage.py sitedir/mycommand'

Related

Django manage.py 1.6.11 suddenly crashes when importing settings

I have an old DJango application that used work fine but suddenly crashes. I use to test it with:
cd /opt/formshare/src/formshare/
export PYTHONPATH=$PYTHONPATH:/opt/formshare/src/formshare
export DJANGO_SETTINGS_MODULE=formshare.settings.default_settings
python manage.py validate
But now I get this error:
(formshare) bash-4.3$ python manage.py validate
Your environment is:"formshare.settings.default_settings"
Traceback (most recent call last):
File "manage.py", line 21, in <module>
execute_from_command_line(sys.argv)
File "/opt/formshare/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/opt/formshare/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/formshare/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/opt/formshare/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/opt/formshare/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/opt/formshare/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/opt/formshare/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'formshare.settings.default_settings' (Is it on sys.path? Is there an import error in the settings file?): cannot import name OrderedDict
I am using:
virtualenv=15.0.2
Python=2.7.11
amqp==2.1.1
billiard==3.3.0.23
celery==3.1.15
dict2xml==1.3
Django==1.6.11
django-braces==1.10.0
django-celery==3.1.16
django-cors-headers==0.13
django-db-readonly==0.3.2
django-digest==1.13
django-filter==0.7
django-guardian==1.2.4
django-nose==1.4.2
django-oauth-toolkit==0.7.2
django-registration-redux==1.1
django-reversion==1.8.4
django-taggit==0.12.1
django-templated-email==0.4.9
djangorestframework==2.4.3
djangorestframework-csv==1.3.3
dpath==1.2.post70
elaphe==0.5.6
FormEncode==1.3.1
gdata==2.0.18
httmock==1.2.2
httplib2==0.9
jdcal==1.3
jsonfield==0.9.23
kombu==4.0.0
librabbitmq==1.5.2
linecache2==1.0.0
lxml==3.4.0
Markdown==2.5
mock==1.0.1
modilabs-python-utils==0.1.5
nose==1.3.7
numpy==1.11.2
oauthlib==2.0.1
openpyxl==2.0.5
pandas==0.12.0
Pillow==2.5.3
poster==0.8.1
psycopg2==2.5.4
pybamboo==0.5.8.1
pylibmc==1.3.0
pymongo==2.7.2
python-dateutil==2.6.0
python-digest==1.7
-e git+https://github.com/qlands/python-json2xlsclient.git#5a39387752d819cb6387f75569dbea9a5288aa6f#egg=python_json2xlsclient
pytz==2014.7
-e git+https://github.com/XLSForm/pyxform.git#cfe8589f40319fa3279b0a83e0d23d49bcbe8408#egg=pyxform
recaptcha-client==1.0.6
requests==2.4.1
savReaderWriter==3.4.2
simplejson==2.6.2
six==1.10.0
South==1.0
traceback2==1.4.0
unicodecsv==0.9.4
unittest2==1.1.0
vine==1.1.3
xlrd==0.9.3
xlwt==0.7.5
I tried to add set the path and setting in the validate but nothing works.
Any idea what could have changed and how to correct it?
The django process doesn't appear to be seeing your formshare.settings.default_settings. Without seeing the project structure, it's hard to know exactly what's going on, but a few things you might check.
If you are using python 2.x, does the formshare/ and the settings/ directory both have an __init__.py file in them?
Try adding /opt/formshare/src/ to the python path instead of (or in addition to) what you have.
One trick that I often try to make sure the python path is correct: while I'm active in my virtualenv, I'll enter a python shell (not django shell) and try something like the following:
import formshare
from formshare import settings
from fomrmshare.settings import default_settings
The error messages that might be generated from those might also help isolate the issue.
Since you activated virtualenv, you have to do something different. Try add2virtualenv in virtualenvwrapper.For more info
http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html#add2virtualenv

Why is my .pythonrc file being run in non-interactive programs?

Context: I started using OSX about a year ago, and I had a kind of screwy python installation. That is, I was using system python, and installed packages with sudo when that seemed to make things work. Now, I'm starting from a fresh OSX install, and trying to do it the Right Way. I've installed python and python3 from brew, and trying to use python3 whenever possible.
Problem: I have a .pythonrc file, which just imports a handful of commonly used packages - mostly standard lib, a few popular nonstandard packages, and a few of my own. In the past, this file has only been run when I start an interactive shell. Now, when using brew python, it is run whenever I run any python program.
There must be some gap in my understanding of the rc file - I thought the purpose was specifically for interactive use. Still, when I use system python, the rc file isn't used - so something is different about my system python (2.7.10 at /usr/bin/python) vs brew python (2.7.12 at /usr/local/bin/python; 3.5.2 at /usr/local/bin/python3). The behavior is the same if I remove everything except a print statement from the rc file.
edit: I realized that the rc file is running because I'm importing ipdb. This makes sense I suppose, but I still don't understand why that would happen in some of the python environments/versions but not others.
edit: https://github.com/gotcha/ipdb/blob/master/ipdb/main.py#L44 this line fails, not sure if this means anything.
Full stacktrace from within .pythonrc:
File "hello.py", line 1, in <module>
from ipdb import set_trace
File "/usr/local/lib/python2.7/site-packages/ipdb/__init__.py", line 7, in <module>
from ipdb.__main__ import set_trace, post_mortem, pm, run # noqa
File "/usr/local/lib/python2.7/site-packages/ipdb/__main__.py", line 51, in <module>
ipapp.initialize([])
File "<decorator-gen-109>", line 2, in initialize
File "/usr/local/lib/python2.7/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 315, in initialize
self.init_code()
File "/usr/local/lib/python2.7/site-packages/IPython/core/shellapp.py", line 263, in init_code
self._run_startup_files()
File "/usr/local/lib/python2.7/site-packages/IPython/core/shellapp.py", line 342, in _run_startup_files
self._exec_file(python_startup)
File "/usr/local/lib/python2.7/site-packages/IPython/core/shellapp.py", line 328, in _exec_file
raise_exceptions=True)
File "/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2469, in safe_execfile
self.compile if kw['shell_futures'] else None)
File "/usr/local/lib/python2.7/site-packages/IPython/utils/py3compat.py", line 288, in execfile
builtin_mod.execfile(filename, *where)
File "~/.pythonrc", line 57, in <module>
import traceback; traceback.print_stack()
You can ask the traceback module:
$ cat .pythonrc
import traceback; traceback.print_stack()
$ cat test.py
import ipdb
Then by running
$ PYTHONSTARTUP="$HOME/.pythonrc" python test.py
you should get a traceback that tells you exactly from where the startup script is being run. Most likely, this is due to a call
start_ipython()
somewhere in the ipdb import.

Django tutorial on pythonanywhere: trouble running the django-admin shell

(Django version 1.9, Python version 3.4.3, using virtual env made with mkvirtualenv --python=/usr/bin/python3.4 django19)
I've been following the Django tutorial very closely, without any problems up til part 5:
https://docs.djangoproject.com/en/1.9/intro/tutorial05/
although, strictly speaking, the problem isn't to do with part 5, but bear with me. I'm following the tutorial in the pythonanywhere framework, because eventually I would like to host a website there. Therefore, I am also following the 'Following the Django tutorial' offered by pythonanywhere:
https://help.pythonanywhere.com/pages/FollowingTheDjangoTutorial
although my problem isn't anticipated in the advice for part 5 in the tutorial. Now the problem- at the point in the Django tutorial which reads:
To check if the bug really exists, using the Admin create a question whose date lies in the future and check the method using the shell
Following the link to the shell, I try (as instructed in the link) to run:
django-admin shell --plain
However I get the following error message
(django19)19:11 ~/mysite $ django-admin shell --plain
Traceback (most recent call last):
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 391, in execute saved_locale = translation.get_language()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 176, in get_language
return _trans.get_language()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 57, in __getattr__
if settings.USE_I18N:
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
During handling of the above exception, another exception occurred:
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 360, in run_from_argv
connections.close_all()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/db/utils.py", line 230, in close_all
for alias in self:
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/db/utils.py", line 224, in __iter__
return iter(self.databases)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/db/utils.py", line 157, in databases
self._databases = settings.DATABASES
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
This error messages recommends setting DATABASES (which is set in mysite/settings.py), by defining the variable DJANGO_SETTINGS_MODULE. So, that's what I did:
export DJANGO_SETTINGS_MODULE="${PWD}/mysite/settings.py"
There are also the required __init__.py files in the mysite and mysite/mysite directories. However now when I run the django-admin command I get:
ImportError: No module named 'mysite/settings'
I can't find anymore documentation or help hereafter. What am I missing? Do I need to set something special somewhere else? Am I setting DJANGO_SETTINGS_MODULE correctly? The ImportError makes it sound like I should set DJANGO_SETTINGS_MODULE to mysite.settings or something similar, but this doesn't work either.
Once you have created your project, use manage.py instead of django-admin to run commands:
python manage.py shell
The manage.py command takes care of the settings for you. If you use django-admin, you have to set DJANGO_SETTINGS_MODULE manually. The DJANGO_SETTINGS_MODULE should be the Python module, e.g. mysite.settings, not a file like /path/to/mysite/settings.py.
Be sure to have your project in the python import search path. Try this
>>import sys
>>sys.path
if the path/directory for your project is not listed, then you need to do
>>sys.path.append('/path/to/my/django/project')
Then assign DJANGO_SETTINGS_MODULE like so:
$export DJANGO_SETTINGS_MODULE=mysite.settings
See Designating Django settings

Django tutorial (using the guide on Heroku), “Please supply the ENGINE value” (yes, I've read other threads)

I've read a lot of similar questions, and I've spent a lot of time trying to work this out myself, but I'm still stuck. Here's my situation:
I'm going through the Django guide on Heroku (https://devcenter.heroku.com/articles/django). I originally started in windows, but after having all sorts of problems I decided it would be a lot easier to switch to linux. I wiped my hard drive and installed Ubuntu 12.10 and Win 7 side by side to dual boot. Everything has been installed with pip (again, following the Heroku guide). I'm using PostgreSQL since it is (supposedly) well-integrated with Heroku. Before I get into what I've tried, here is the error (it's from near the end of the tutorial):
(venv)wtodom#wubuntu:~/hellodjango$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
If I try to specify the settings file with its absolute path to make sure it uses the right one I get this:
(venv)wtodom#wubuntu:~/hellodjango$ python manage.py syncdb --settings=/home/wtodom/hellodjango/hellodjango/settings.py
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
from django.db import models
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/wtodom/hellodjango/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings '/home/wtodom/hellodjango/hellodjango/settings.py' (Is it on sys.path?): Import by filename is not supported.
A lot of the similar questions had people editing the wrong settings.py file. I know I edited the right one. Here's a cat of it (on gist since it's kinda long) - https://gist.github.com/wtodom/4736303. I've tried every combination I can think of for the data in there, including empty strings - no difference.
Other posts I've read have had people who had issues with the Django version they were running. Mine is a fresh install through and through, so it's not that.
Some people had issues with Django not being on the path. If I open a python shell from the projects root directory I can import things, so it's not that.
Some people didn't have values in their settings.py file, but as you can see from the gist, I do. I also tried running the command (python manage.py syncdb) both with and without pgadmin running and logged in.
On that note, here is a screencap of pgadmin showing that I have databases created and up: http://i.imgur.com/CXD2AWo.png
Here's what I get when I \l in PostgreSQL (another gist since SO killed the formatting): https://gist.github.com/wtodom/4736359
While I'm at it, here's a \du listing: https://gist.github.com/wtodom/4736442
I made sure that my manage.py has os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings") in it.
Everything in the Heroku tutorial worked without a hitch in Ubuntu up until I tried to sync the db locally (python manage.py syncdb). I can run the same command through heroku and it works fine (heroku run python manage.py syncdb).
I'm sure I'd forgotten probably something relevant that I've tried or read. I've spent about 6 hours reading and trying to get this thing going, just on this one error. I don't really know what else to try.
Also, I'm really new to databases and non-.NET web development (I've worked on projects, but never set one up), so if you know what's wrong with my setup please try to be clear. Thank you very much!
Heroku and your local machine usually need different database settings. A common way to handle that is to first list your local database settings in the settings.py file, then do a check to see if you're code is currently running on Heroku, and if so, override your database settings with what Heroku needs. That allows a single settings.py file to work in both environments.
Heroku creates an environment variable called DATABASE_URL containing the database URL string. A common way to check whether your code is running on Heroku is to check for that environment variable. Then, if it exists, use the dj_database_url module, which knows how to parse that string into the dictionary that Django needs for its configuration.
The only thing incorrect in your code is that you didn't check for the environment variable first before calling dj_database_url.config(). This means that dj_database_url, which normally should only run within Heroku, was running on your local machine too. Since your local machine almost certainly doesn't have the DATABASE_URL environment variable set, dj_database_url returned an empty dictionary. So, your code is overwriting your local database configuration with an empty dictionary when it's not run on Heroku. Django looks in that dictionary for the information it needs, can't find it, and raises an error.
To fix the problem, add a check for DATABASE_URL before using dj_database_url.
Change this part at the end of settings.py:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
To this:
if os.environ.get('DATABASE_URL', None):
import dj_database_url
DATABASES['default'] = dj_database_url.config()

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

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
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

Categories

Resources