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

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

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

Python suddenly has error: "No module named unittest." I'm not running a unit test

I have a Django application, which very suddenly started giving me an error. I made a code change, restarted the application, and now I can't get rid of this error. I really don't think that I did anything else in between the two runs.
The error is ImportError: "No module named unittest" I don't know if it thinks it should be running a unit test or if this just happens to be the first thing to fail.
I have tried running it both from Eclipse and from the CMD line with manage.py runserver. Same error. (This is an update. previously I had only tried from Eclipse.) A brand-new project made in Eclipse has the same error.
This happens with any web application (using runserver), so it's not my code. I also reverted back to older code that worked fine before.
I have tried restarting my computer.
I am able to run "regular'(not a web application) python programs from the cmd line. So it does find Python.
I honestly have no idea what to do at this point, except to reinstall Python, which I'd like to avoid. Anyone?
NEW Stack trace (Update: previous was from Eclipse and just showed pydev errors. Run from cmd line it shows more python.)
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02FE2710>>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 93, in inner_run
self.validate(display_num_errors=True)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate
self.load_app(app_name)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 18, in <module>
from django.contrib.auth.hashers import (
File "C:\Python27\lib\site-packages\django\contrib\auth\hashers.py", line 8, in <module>
from django.test.signals import setting_changed
File "C:\Python27\lib\site-packages\django\test\__init__.py", line 6, in <module>
from django.test.testcases import (TestCase, TransactionTestCase,
File "C:\Python27\lib\site-packages\django\test\testcases.py", line 35, in <module>
from django.test import _doctest as doctest
File "C:\Python27\lib\site-packages\django\test\_doctest.py", line 104, in <module>
import unittest, difflib, pdb, tempfile
ImportError: No module named unittest
Well, don't know if I'd call it an answer, but I reinstalled Python and now it's working. Now I just have to reinstall my 10 or so libraries to fix the runtime errors.
unittest module is integral part of python, which causes import error when django tries to import it. You must have somehow deleted some python package, or have corrupted installation.

First steps Django errors

I need to ask because I'm starting in Django and it was impossible for me to continue with the tutorial that I'm following. I've just completed a Python course, I know the basics of python. The case is that I've installed Django in my mac and it's OK because when I do in the IDLE the
import django
print django.VERSION
It makes a good answer without errors in IDLE (is the software that I use to write python code). But when I execute in the Terminal the command:
python manage.py runserver
It raises this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Frameworks/Python.framework/Versions/7.3/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 "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
I also want to ask you some questions:
Can I use XAMPP instead of Django? How?
What is Django used for exactly?
I've installed PyDev in Eclipse. How can I set Django to execute code properly?
call command django-admin startproject xxx under the target directory. You can get three .py files: setting.py, urls.py and manage.py. And you can execute python manage.py runserver command
I think it's slightly outdated now, but I'd seriously recommend going through the Djangobook examples. It'll explain how to set up Django properly, and give a pretty good foundation in how to use it.

python django - no module psycopg2.extension even after installing compiled version psycopg2-2.4.5.win32-py2.7.‌exe

I am using python django on windows,and trying to deploy to heroku . When i tried to install psycopg2 using pip,
pip install psycopg2
i got error :
unable to find vcvarsall.bat
Then i found that i need to install visual studio 2008 (or) i can directly download and install compiled version , so downlaoded from this link :
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Filename i downloaded : psycopg2-2.4.5.win32-py2.7.‌exe
Even after installing this i am getting error : no module named psycopg2.extensions
So, what more should i do ?
D:\mycode\python\mysite>heroku run python manage.py syncdb
Running python manage.py syncdb attached to terminal... up, run.1
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site- packages/django/core/management/__i
nit__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/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 "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/sql
.py", line 6, in <module>
from django.db import models
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line24, in load_backend
return import_module('.base', backend_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 13, in <module>
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/backends/postgre
sql_psycopg2/creation.py", line 1, in <module>
import psycopg2.extensions
ImportError: No module named psycopg2.extensions
D:\mycode\python\mysite>
While isntalling psycopg2 both by pip and easy_install, installdidnt work as i got this error : unable to find vcvarsall.bat with some msg : no previsouly included directores matching 'doc\src_build'
Thanks
Despite some claims on the Internet, psycopg2 DOES work in a VirtualEnv.
Download the correct version of win-psycopg2. Typically I use 32-bit Python 2.7 so I got psycopg2-2.4.5.win32-py2.7-pg9.1.3-release.exe.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
This worked for me, hope it works for you.
Take a look at http://slacy.com/blog/2010/09/python-unable-to-find-vcvarsall-bat/. It seems you need to install Microsoft Visual Studio Express to solve the vcvarsall.bat issue.
Pretty crazy...
Binaries from this link:
http://www.stickpeople.com/projects/python/win-psycopg/
In settings.py it should look like this in db settings
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
Yes, this work!

Django - First project - runserver is an invalid syntax

I decided to try developing on python with django, while python is new to me right now.
[I'm using Windows 7 64bit]
Then, i installed python 2.7, added C:\Python27\;C:\Python27\Scripts; to PATH variable.
Next, i installed Eclipse Classic (last version) and installed PyDev, and Django.
I created my first project on Eclipse as a Django project but couldn't run it.
I'm trying (Right click on my project)-> Run as -> PyDev: Django, and i have the following console log:
Validating models...
Traceback (most recent call last): File "C:\Users\Matan\workspace\FirstSample\manage.py", line 10, in <module>
execute_from_command_line(sys.argv) File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
utility.execute() File "C:\Python27\Lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__) File "C:\Python27\Lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options) File "C:\Python27\Lib\site-packages\django\core\management\commands\runserver.py", line 69, in handle
self.run(*args, **options) File "C:\Python27\Lib\site-packages\django\core\management\commands\runserver.py", line 80, in run
and the list goes on...
So i tried to run the project with the python console, using:
import Django
manage.py runserver
and i have the following syntax error:
File "<stdin>", line 1
manage.py runserver
^ SyntaxError: invalid syntax
What is the problem with running my project ? How can i solve this?
Thanks.
Edit:
After trying to run the project with the following command:
python manage.py runserver on the project directory, i receive the following traceback log: Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <dja ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x000000 0002688748>> Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\core\management\commands\runserver. py", line 91, in inner_run
self.validate(display_num_errors=True) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app) File "C:\Python27\lib\site-packages\django\core\management\validation.py", lin e 23, in get_validation_errors
from django.db import models, connection File "C:\Python27\lib\site-packages\django\db\__init__.py", line 40, in <modul e>
backend = load_backend(connection.settings_dict['ENGINE']) File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in
__geta ttr__
return getattr(connections[DEFAULT_DB_ALIAS], item) File "C:\Python27\lib\site-packages\django\db\utils.py", line 92, in
__getitem
__
backend = load_backend(db['ENGINE']) File "C:\Python27\lib\site-packages\django\db\utils.py", line 24, in load_back end
return import_module('.base', backend_name) File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im port_module
__import__(name) File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 16 , in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo dule named MySQLdb
Download the pre-compiled python-mysql package for Windows, install it, then run the command again.
While you are there, you might as well also install setuptools if you haven't already.
Error loading MySQLdb module: No mo dule named MySQLdb
You have configured your settings to you MySQL but you have not installed MySQL-python:
pip install MySQL-python
You must be in the project directory to run the python manage.py runserver command. You also need to (1) set the PYTHONPATH environment variable to include your project directory's parent and (2) set the DJANGO_SETTINGS_MODULE environment variable to yourproject.settings
If you've done it correctly, you should be able to go to an unrelated directory (i.e. not your project directory) and do the following import in a python shell:
c:\temp> python
...
>>> from django.conf import settings
the settings module that is imported should then be the one in your project directory...

Categories

Resources