UPDATED: See the bottom


The first step of the Django tutorial instructs you to create a new project like this

django-admin.py startproject mysite2

When I do that, it fails:

R:\jeffy\programming\sandbox\python\django_files\tutorial>django-admin.py startproject mysite
Traceback (most recent call last):
  File "C:\applications\programming\python_341\Scripts\django-admin.py", line 2, in ?
    from django.core import management
  File "c:\applications\programming\python_341\Lib\site-packages\django\core\management\__init__.py", line 55
    except ImportError as e:
                        ^
SyntaxError: invalid syntax

I also tried

python django-admin.py startproject mysite2

Which also fails:

R:\jeffy\programming\sandbox\python\django_files\tutorial>python django-admin.py startproject mysite2
python: can't open file 'django-admin.py': [Errno 2] No such file or directory

But when I do this, it works:

python C:\applications\programming\python_341\Lib\site-packages\django\bin\django-admin.py startproject mysite2

It gives no response, but the directory is created:

R:\jeffy\programming\sandbox\python\django_files\tutorial>dir mysite2
 Volume in drive R is internal_files
 Volume Serial Number is 9ADC-75EC

 Directory of R:\jeffy\programming\sandbox\python\django_files\tutorial\mysite2

07/31  02:33 PM    <DIR>          .
07/31  02:33 PM    <DIR>          ..
07/31  02:33 PM               250 manage.py
07/31  02:33 PM    <DIR>          mysite2
               1 File(s)            250 bytes
               3 Dir(s)  208,804,356,096 bytes free

PYTHONPATH is equal to

c:\applications\programming\python_341\Lib\site-packages\

and I confirmed that both

C:\applications\programming\python_341\
C:\applications\programming\python_341\Scripts

are in PATH.

Any ideas on how to reduce

python C:\applications\programming\python_341\Lib\site-packages\django\bin\django-admin.py startproject mysite2

to

django-admin.py startproject mysite2

As in the Django tutorial?

Thank you.


UPDATE

Full path, line separated.

C:\applications\programming\python_341\;
C:\applications\programming\python_341\Scripts;
C:\applications\utilities\shell_utilities;
C:\applications\programming\;
.;
C:\Program Files\Common Files\ArcSoft\Bin;
C:\Program Files\Common Files\Microsoft Shared\Windows Live;
C:\Program Files\Windows Live\Shared;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Windows\system32;
C:\applications\audio\LilyPond\usr\bin;
C:\applications\internet\LinkChecker;
C:\applications\programming\DependencyFinder-1.2.1-beta4\bin;
C:\applications\programming\apache-ant-1.8.1\bin;
C:\applications\programming\apache-maven-3.1.1\bin;
C:\applications\programming\gradle-1.9\bin;
C:\applications\programming\jdk_7_51\bin;
C:\applications\programming\unix_utils\usr\local\wbin\;
C:\applications\video\quicktime\QTSystem\;

As suggested, I entirely commented out

C:\applications\programming\python_341\Scripts\django-admin.py

and added

import sys; print(sys.version, sys.executable)

to the top. Here is the result of running

django-admin.py startproject mysite2

again:

django-admin.py startproject mysite3 ('2.4.5 (#1, Dec 15 2009, 16:41:19) \n[GCC 4.1.1]', 'C:\\applications\\audio\\LilyPond\\usr\\bin\\python.exe')

And wouldn't you know it

C:\applications\audio\LilyPond\usr\bin

is part of the path.

After taking these steps

  1. uninstalling LilyPond, and eliminating it from the path
  2. re-installing Python 3.4.1 (although I'm not sure that was necessary)
  3. Associating ".py" files to open with C:\applications\programming\python_341\python.exe by default (I did this via right clicking C:\applications\programming\python_341\Scripts\django-admin.py in explorer, selecting "Open with...", and then browsing to python.exe and selecting it.)

this works:

python C:\applications\programming\python_341\Scripts\django-admin.py startproject mysite5

But both of these

django-admin.py startproject mysite5
C:\applications\programming\python_341\Scripts\django-admin.py startproject mysite5

fail with

Usage: django-admin.py subcommand [options] [args]

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on exception
  --version             show program's version number and exit
  -h, --help            show this help message and exit

Type 'django-admin.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
    check
    cleanup
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    runfcgi
    runserver
    shell
    sql
    sqlall
    sqlclear
    sqlcustom
    sqldropindexes
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlsequencereset
    startapp
    startproject
    syncdb
    test
    testserver
    validate

I'm guessing associating *.py to python.exe, at least doing it via explorer, was a mistake.

Any ideas?

  • It appears that you have an old python still in your PATH. Can you provide the whole PATH? – Nick Humrich Jul 31 '14 at 18:50
  • @Humdinger Yeah. It turns out I have two different versions of python in the path. Dealing with it now. Will update when I finish. – aliteralmind Jul 31 '14 at 19:34
  • @Humdinger: Updated the question-post. One problem down, hopefully not too many to go. – aliteralmind Jul 31 '14 at 19:56
  • Still probably a path problem. "If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed." from docs.djangoproject.com/en/dev/howto/windows – Nick Humrich Jul 31 '14 at 20:27
  • @Humdinger: Followup: stackoverflow.com/questions/25069236/… – aliteralmind Jul 31 '14 at 21:28

The other suggestions are valid. Check your paths, check both user and system PATH variables. Once you make sure only the right remains, try again.

Now, a slightly different approach. Sometimes, it is necessary to have multiple versions of a software (including python). This is why it is highly recommended to use virtualenv (and virtualenvwrapper) to isolate python environments. With virtualenv you can install the version of python you need for you code without clashing with other python versions on your system. Python3 comes with virtualenv, but you can read more on virtualenv here and virutalenvwrapper here.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.