如何减少" python ... PATH ... django-admin.py startproject myprojname" to" django-admin.py startproject myprojname"?

时间:2014-07-31 18:41:48

标签: python django python-3.x

更新: 请参见底部


Django教程的first step指示您创建一个像这样的新项目

django-admin.py startproject mysite2

当我这样做时,它失败了:

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

我也试过

python django-admin.py startproject mysite2

哪个也失败了:

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

但是当我这样做时,它起作用:

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

它没有响应,但创建了目录:

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

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

我确认了两者

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

位于PATH

有关如何减少的任何想法

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

django-admin.py startproject mysite2

与Django教程一样?

谢谢。


更新

完整路径,分隔行。

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

作为suggested,我完全注释掉了

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

并添加了

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

到顶部。这是运行

的结果
django-admin.py startproject mysite2

再次:

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

你不知道吗

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

是路径的一部分。

采取这些步骤后

  1. 卸载LilyPond,并将其从路径中删除
  2. 重新安装Python 3.4.1(虽然我不确定是否有必要)
  3. 默认情况下将“.py”文件与C:\ applications \ programming \ python_341 \ python.exe关联(我是通过右键单击资源管理器中的C:\applications\programming\python_341\Scripts\django-admin.py,选择“打开方式...”,然后浏览到python.exe并选择它。)
  4. 这有效:

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

    但这两个

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

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

    我猜测将*.py关联到python.exe,至少通过资源管理器进行关联,这是一个错误。

    有什么想法吗?

1 个答案:

答案 0 :(得分:0)

其他建议有效。检查路径,检查用户和系统PATH变量。一旦确定只剩下右侧,请再试一次。

现在,采用略有不同的方法。有时,有必要拥有多个版本的软件(包括python)。这就是强烈建议使用virtualenv(和virtualenvwrapper)来隔离python环境的原因。 使用virtualenv,您可以安装代码所需的python版本,而不会与系统上的其他python版本发生冲突。 Python3附带了virtualenv,但你可以在virtualenv here和virutalenvwrapper here上阅读更多内容。