Django: Can not get django-admin.py to run anything - django

System: Windows 7x64
Django v. 1.4
Python v. 3.2
First time working with Django or python and I am beating my head against the wall. I have installed everything for Django according to the install instructions. The only step I skipped was the 'optional' virtualenv installation.
I am attempting to run the tutorial on djangoproject.com and I can't get startproject to work. Here is my issues.
When attempting to use 'django-admin.py startproject mysite' or even just 'django-admin.py help' functions I get the following:
Traceback (most recent call last):
File "C:\Python32\Scripts\django-admin.py", line 2, in
from django.core import management File "C:\Python32\lib\site-packages\django\core\management__init__.py",
line 54
except ImportError,e:
^
SyntaxError: invalid syntax
Where the ^ is pointing to the comma.
I have checked the permissions for the folder I am in and everything appears to be good there. What am I doing wrong?

Django doesn't work with Python 3 (yet).
Install 2.7 instead.

You might also stick to Python 3.X and get django 1.5 that is currently in beta phase.

Python 3.3 offers experimental support. django-admin.py still won't run properly, but here's a workaround for you:
You can call the django-admin subcommands directly from your own python script.
from django.core import management
management.call_command("startproject", "mysite")
Almost everything else should be done from the manage.py file it generates, which should work fine with:
python manage.py runserver
or whatever command you're looking for. You may also be using "python33" instead of python.

General answer: that syntax line isn't valid in Python 3.2 (Django doesn't work with Python 3 yet). Here's a list of the 2.x versions you can use with particular versions of Django.
Specific answer: According to PEP-3110, the syntax for exceptions changed from except Exception, e to except Exception as e in Python 3, which is why that error's showing up.

Related

How to overcome ImportError: cannot import name XXXX

I have pulled some working Django code from a repo and am trying to set up my local windows 7 dev environment. I have what I think is a suitable version of Python (2.7.6) and a copy of Django 1.5.4.
When I tried python manage.py runserver, I got various ImportErrors.
One by one, I did a pip install XXXX and they went away.
But now I am stuck with this error;
ImportError: cannot import name parse_html_config
I'm only a few days into Python & Django so am unclear - but I think this import is part of commandtools package, so I did pip install commandtools. I got the message that commandtools was already installed.
When I search my project, I can't find from XXXX import parse_html_config anyway, so I don't know where to look next, can anyone help please?
The whole output is;
(swoopenv) C:\django workspace\swoopenv\swoop\swoop>python manage.py runserver
C:\Python27\Lib\site-packages\django\core\management\__init__.py:465: DeprecationWarning: The 'execute_manager' function is deprecated, you
likely need to update your 'manage.py'; please see the Django 1.4 release notes (https://docs.djangoproject.com/en/dev/releases/1.4/).
DeprecationWarning)
C:\Python27\Lib\site-packages\django\core\management\__init__.py:409: DeprecationWarning: The 'setup_environ' function is deprecated, you li
kely need to update your 'manage.py'; please see the Django 1.4 release notes (https://docs.djangoproject.com/en/dev/releases/1.4/).
DeprecationWarning)
C:\Python27\Lib\site-packages\django\conf\__init__.py:221: DeprecationWarning: You have no filters defined on the 'mail_admins' logging hand
ler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logge
d
DeprecationWarning)
ImportError: cannot import name parse_html_config

Django Install Wierdness - Mac OSX 10.8.5 and Macport Python 2.7.6 - Django/Python/Unix beginner

I've found a lot of posts on Macports/Django install issues but none seem to quite address my situation.
Installed Django using Macports from the command line using
sudo port install py27-django
This seemed to work fine. I opened up IDLE and was able to import django. The following bit of code
import django
from django.core import management
print django.VERSION
returns
(1, 5, 1, 'final', 0)
Which I take to mean I have the final version of Django 1.5.1 installed. So, all seems to be well.
However, now I switch over to my Django tutorial to get learning and I am asked to type this into the command line to confirm that Django is installed:
python -c "import django; print(django.get_version())"
and get the following error:
> File "<string>", line 1, in <module> ImportError: No module named
> django
Some other bits of data. Here's my $PATH:
/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
Finally, the command
django-admin.py startproject mysite
returns
-bash: django-admin.py: command not found
But the command
django-admin-2.7.py startproject mysite
works (creates a new directory called mysite in the working directory). I read somehwere that Macports renames the django-admin file.
I've only been working with Unix for a few weeks so this is a bit confusing. It seems like I have Django on my system, but perhaps the python I am trying to access from my command line is a different python from that which Macports uses.
Any help appreciated!
Dennis
You will need to set your PYTHONPATH environment variable from your terminal to reference your django install. IDLE probably did this for you, but in another shell you'll need to set it. You can set it in your terminal permanently by setting it in ~/.bashrc or ~/.bash_profile (or whatever your terminal shell is).
Your PATH starts with /Library/Frameworks/Python.framework/Versions/2.7/bin so when you type python you get the python in that directory which is the Apple supplied one nut you have installed Django for the Macports one so python does not see it.
To fix you need to have /opt/local/bin earlier on the path than the /Library one. even better remove that /Library entry and use port select python ... to choose which python to run the Macports 2.7 or Apple's or others
As for the django-admin-2.7.py issue, Macports allows you to have several versions of python at once so code depending on eth version has the version add into the script names e.g. you could have a django-admin-2.6.py as well if you installed the py26-django package. This also applies to python itself however python also adds into the port select mechanism so you set a default version.

Installing Django on Jython

I am trying to install Django with Jython.
System - Windows 7, 64bit
Jython - 2.5.4rc1 (installed succesfully)
Django - 1.5 (not yet installed)
When I am in the unpacked Django-1.5 directory and try to run the command line instruction
'jython setup.py install'
I get the error message:
Traceback (most recent call last):
File "setup.py", line 84, in (module)
version = __import__('django').get_version()
File "E:\jython2.5.4rc1\bin\Django-1.5\django\__init__.py", line 6, in get_version
from django.utils.version import get_version
File "E:\jython2.5.4rc1\bin\Django-1.5\django\utils\version.py", line 1
SyntaxError: future feature unicode_literals is not defined
I can imagine that it is something very simple that only an ABSOLUTE NEWBIE could ever get wrong. So we all know what I am :)
Many thanks for any help in taking my first wobbly steps.
Django 1.5 has dropped support for Python 2.5. Therefore, you have to use a Jython 2.7 alpha release if you want to use Django 1.5 with Jython. Please use Django 1.4 if you want to keep using Django on a stable Jython version.
https://docs.djangoproject.com/en/dev/howto/jython/

Django South syncdb gives a SyntaxError

I installed South using pip.
Following the official guide (http://south.readthedocs.org/en/latest/installation.html#installation)
I add 'south', to my installed_apps, run manage.py syncdb, get this:
*Long Traceback ending in south\management\commands\syncdb.py, line 52
except Import Error, exc:
SyntaxError: invalid syntax
Take south away, run syncdb, everything is fine. What gives?
UPDATE: South only works on Python 2.x so installing 2.7 did the trick. Thank you IRC.
I do not know what you may have done wrong, but to do the work you need to just south of 3 small steps, described previously by you.
1) pip install south
2) Add the 'south' in your INSTALLED_APPS the end of all "django.contrib"
3) run python manage.py syncdb
With these steps your syncdb will be different and, from this point forward, you should normally use the south.
I did a video recently (in Portuguese), showing how to install and run south with a project already started, maybe this video can help you http://bit.ly/XffRGy
I got the same error using python 3.2.3. I my case this is a non-backwards compatible change from python 2.*. I went to the source file and deleted the ", exc" you will find at the end of an except statement. This fixed the error in question, however you will get more errors from there. I tried running 2to3 on the whole south directory and and not getting and code specific errors anymore. Unfortunalty I am now getting and error "NameError: global name 'exc' is not defined" but with no traceback. I have been stuck here for a while, but at least this is progress. I will report if I get this thing working.
[Check here for info regarding the specific incompatibility. Under the heading "Changes Already Present In Python 2.6"]
(http://docs.python.org/release/3.1.3/whatsnew/3.0.html)

Django1.4 not compatible with Python3.2?

I installed Django1.4 on Win 7 with python3.2. But when I run django-admin.py startproject mysite on command prompt I get errors like Syntax error: Invalid Syntax. It shows that there is an error at print ''.join ....... I see that print is missing (). I fixed one Syntax error already.
Is it incomparability issue?
What do you suggest should I do?
Django doesn't officially support Python 3.x yet. Use it with Python 2.7.
Here's the official latest news about Django on Python 3: https://www.djangoproject.com/weblog/2012/mar/13/py3k/
There is an unofficial experiment in supporting Python 3 with a common code base: https://bitbucket.org/vinay.sajip/django/