Re: SyntaxError Creating New Project

185 views
Skip to first unread message

Kurtis Mullins

unread,
Aug 22, 2012, 10:26:12 PM8/22/12
to django...@googlegroups.com
Very weird. I ran the syntax and did not receive a syntax error. I just checked on the documentation and it does say Python 2.5 is required, which as you mentioned you have installed. 

Maybe double-check to make sure that you're executing this with the right Python executable? I'm running Python 2.7 if it makes a difference.

Here's a reference to the file that's giving you the error:

On Wed, Aug 22, 2012 at 5:00 PM, Bestrafung <music...@gmail.com> wrote:
I'm new to Django and though I've dabbled with Linux off and on for a decade I'm still learning so please go easy on me. I'm following this guide to setup a Django 1.4.1 test project. So far I've setup Python 2.5 with MySQL-python-1.2.3 and setuptools, setup mod_wsgi, and edited .bash_profile. I've downloaded Django 1.4.1 (not trunk) and so far everything looks good. As soon as I run "django-admin.py startproject testproject" I receive an error and am having trouble resolving it. I apologize if this has come up before bet a quick search wasn't helpful. Thanks in advance for any assistance, the error is below:

[-bash-3.2 root@server1: /home/username/sites/domain.com] # /home/username/sites/domain.com/django/bin/django-admin.py startproject testproject
Traceback (most recent call last):
  File "/home/username/sites/domain.com/django/bin/django-admin.py", line 2, in ?
    from django.core import management
  File "/home/username/sites/domain.com/django/__init__.py", line 15
    parts = 2 if version[2] == 0 else 3
               ^
SyntaxError: invalid syntax
[-bash-3.2 root@server1: /home/username/sites/domain.com] #

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/WszNLKVNcxcJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Alexis Roda

unread,
Aug 23, 2012, 12:05:16 AM8/23/12
to django...@googlegroups.com
Al 22/08/12 23:00, En/na Bestrafung ha escrit:
> I'm new to Django and though I've dabbled with Linux off and on for a
> decade I'm still learning so please go easy on me. I'm following this
> guide
> <http://blog.perplexedlabs.com/2008/11/10/setup-python-25-mod_wsgi-and-django-10-on-centos-5-cpanel/>
> to setup a Django 1.4.1 test project. So far I've setup Python 2.5 with
> MySQL-python-1.2.3 and setuptools, setup mod_wsgi, and edited
> .bash_profile. I've downloaded Django 1.4.1 (not trunk) and so far
> everything looks good. As soon as I run "django-admin.py startproject
> testproject" I receive an error and am having trouble resolving it. I
> apologize if this has come up before bet a quick search wasn't helpful.
> Thanks in advance for any assistance, the error is below:
>
> [-bash-3.2 root@server1: /home/username/sites/domain.com] #
> /home/username/sites/domain.com/django/bin/django-admin.py
> startproject testproject
> Traceback (most recent call last):
> File "/home/username/sites/domain.com/django/bin/django-admin.py",
> line 2, in ?
> from django.core import management
> File "/home/username/sites/domain.com/django/__init__.py", line 15
> parts = 2 if version[2] == 0 else 3
> ^
> SyntaxError: invalid syntax
> [-bash-3.2 root@server1: /home/username/sites/domain.com] #

The "var = value if predicate else value" syntax was introduce in python
2.5, so it seems like the python interpreter that's being used to run
django-admin.py is older.

Try executing python and look at the version number. Check the shebang
in the 'django-admin.py' too.

As a workaround execute:

/path/to/python2.5 /path/to/django-admin.py startproject testproject



HTH

Karen Tracey

unread,
Aug 23, 2012, 12:08:00 AM8/23/12
to django...@googlegroups.com
On Wed, Aug 22, 2012 at 5:00 PM, Bestrafung <music...@gmail.com> wrote:
I'm new to Django and though I've dabbled with Linux off and on for a decade I'm still learning so please go easy on me. I'm following this guide to setup a Django 1.4.1 test project. So far I've setup Python 2.5 with MySQL-python-1.2.3 and setuptools, setup mod_wsgi, and edited .bash_profile. I've downloaded Django 1.4.1 (not trunk) and so far everything looks good. As soon as I run "django-admin.py startproject testproject" I receive an error and am having trouble resolving it. I apologize if this has come up before bet a quick search wasn't helpful. Thanks in advance for any assistance, the error is below:


[-bash-3.2 root@server1: /home/username/sites/domain.com] # /home/username/sites/domain.com/django/bin/django-admin.py startproject testproject
Traceback (most recent call last):
  File "/home/username/sites/domain.com/django/bin/django-admin.py", line 2, in ?
    from django.core import management
  File "/home/username/sites/domain.com/django/__init__.py", line 15
    parts = 2 if version[2] == 0 else 3
               ^
SyntaxError: invalid syntax
[-bash-3.2 root@server1: /home/username/sites/domain.com] #
That error indicates the python executable processing django-admin.py is Python 2.4 level, not 2.5. With Python 2.5 I can import django at level 1.4.1:

kmt@lbox 20:04:15: ~/software/web
--> python
Python 2.5.2 (r252:60911, Jan 20 2010, 23:16:55)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> quit()

If I try with Python 2.4 level, I get the error you are seeing:

kmt@lbox 20:04:45: ~/software/web
--> python2.4
Python 2.4.5 (#2, Jan 21 2010, 19:44:35)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/kmt/django/Django-1.4.1/django/__init__.py", line 15

    parts = 2 if version[2] == 0 else 3
               ^
SyntaxError: invalid syntax
>>>

You may have python 2.5 installed, but you seem to have 2.4 also, and 2.4 is what's getting used for the command you are running.
 
Karen
--
http://tracey.org/kmt/

Bestrafung

unread,
Aug 27, 2012, 1:51:22 PM8/27/12
to django...@googlegroups.com
Thank you all for the tips. I was pretty sure I tried using the full path to the 2.5 install with the same error but I'll check again. I'll let you know what I find.

Bestrafung

unread,
Aug 27, 2012, 2:06:45 PM8/27/12
to django...@googlegroups.com
I ran python and checked the version number. This is what I get:

[-bash-3.2 root@server1: ~] # python
Python 2.5 (r25:51908, Aug 20 2012, 11:55:47)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Type "help", "copyright", "credits" or "license" for more information.
>>>

When I run "import django" I get:


>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django


I assumed this was normal since the guide I'm following has all of the django setup in the user's home directory. Is this the problem? I will keep looking into it, the guide had me enter export PYTHONPATH='$PYTHONPATH:/home/username/sites/domain.com' in the user's .bash_profile, since I am logged in as root should I add that to the /root/.bash_profile?

Bestrafung

unread,
Aug 27, 2012, 3:05:23 PM8/27/12
to django...@googlegroups.com
Ok, I think it's worked out now. I added the export line to the root .bash_profile and then changed the shebang in django-admin.py to "/opt/python2.5/bin python" and now everything seems to be working. If anyone is working on an older Red Hat/CentOS system and has to follow the guide I'm following I hope this helps them.

Melvyn Sopacua

unread,
Aug 27, 2012, 10:07:12 PM8/27/12
to django...@googlegroups.com
On 27-8-2012 17:05, Bestrafung wrote:
> Ok, I think it's worked out now. I added the export line to the root
> .bash_profile and then changed the shebang in django-admin.py to
> "/opt/python2.5/bin python" and now everything seems to be working.

I imagine there's a typo there and no space, but a forward slash.
> If
> anyone is working on an older Red Hat/CentOS system and has to follow the
> guide I'm following I hope this helps them.
>
It's kind of weird that this fix works without problems. You should try
the following in your project directory:
/opt/python2.5/bin/python manage.py shell
On the shell you get then:
>>> from django.db import models
>>> print models.__file__

I'm quite interested what that shows since your installation seems to be
all over the place.

--
Melvyn Sopacua

Bestrafung

unread,
Sep 6, 2012, 2:58:43 PM9/6/12
to django...@googlegroups.com
I've been extremely busy with other projects and just got back to this. It would appear you are correct about it not working correctly. I'm new to all of this and I'd have been lost long ago without that guide but it is severely lacking. Below is the result of the manage.py command.

[-bash-3.2 root@server1: /home/username/sites/domain.com/django/bin/testproject] # /opt/python2.5/bin/python manage.py

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

Bestrafung

unread,
Sep 18, 2012, 8:19:58 PM9/18/12
to django...@googlegroups.com
I restarted from the beginning using the previously mentioned guide but also a very helpful post on the cpanel.net forums and there were some missed steps and minor misconfigurations. Everthing seems to be working on the webserver side but now have some strange permissions issues that'll go into another post. I hope this helps anyone else interested in setting up Django on a CentOS 5.x cPanel system.

Stephen Anto

unread,
Sep 20, 2012, 4:20:33 AM9/20/12
to django...@googlegroups.com
Hi,

Just follow these 7 steps to start new project http://f2finterview.com/web/Django/17/ For more http://f2finterview.com/web/Django

On Wed, Sep 19, 2012 at 1:49 AM, Bestrafung <music...@gmail.com> wrote:
I restarted from the beginning using the previously mentioned guide but also a very helpful post on the cpanel.net forums and there were some missed steps and minor misconfigurations. Everthing seems to be working on the webserver side but now have some strange permissions issues that'll go into another post. I hope this helps anyone else interested in setting up Django on a CentOS 5.x cPanel system.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/GukGIRK-mpwJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Daniel Roseman

unread,
Sep 20, 2012, 10:05:31 AM9/20/12
to django...@googlegroups.com
On Thursday, 20 September 2012 05:20:56 UTC+1, Stephen Anto wrote:
Hi,

Just follow these 7 steps to start new project http://f2finterview.com/web/Django/17/ For more http://f2finterview.com/web/Django



Stephen, please stop spamming this list by posting the same link to your site over and over again.
--
Daniel. 

Stephen Anto

unread,
Sep 20, 2012, 10:42:11 AM9/20/12
to django...@googlegroups.com
Hi Daniel,

I am not spamming. just inform you that how to create django projects with initial steps.

I just replied for your 'SyntaxError Creating New Project' title.

I have prepared to make this answer for your questions. Is it related your query or not?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/DmRKpNppH9MJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reply all
Reply to author
Forward
0 new messages