[英]How to reduce “python …PATH…django-admin.py startproject myprojname” to “django-admin.py startproject myprojname”?
UPDATED: See the bottom 更新:请看底部
The first step of the Django tutorial instructs you to create a new project like this Django教程的第一步指示您创建一个像这样的新项目
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 PYTHONPATH
等于
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
. 在
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? 如Django教程中所述?
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 采取这些步骤之后
C:\\applications\\programming\\python_341\\Scripts\\django-admin.py
in explorer, selecting "Open with...", and then browsing to python.exe and selecting it.) C:\\applications\\programming\\python_341\\Scripts\\django-admin.py
来执行此操作,选择“使用...打开”,然后浏览到python.exe并选择它。) 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. 我猜测将
*.py
关联到python.exe
,至少是通过资源管理器执行,这是一个错误。
Any ideas? 有任何想法吗?
The other suggestions are valid. 其他建议是有效的。 Check your paths, check both user and system PATH variables.
检查您的路径,检查用户和系统PATH变量。 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).
有时,必须具有一个软件的多个版本(包括python)。 This is why it is highly recommended to use virtualenv (and virtualenvwrapper) to isolate python environments.
这就是为什么强烈建议使用virtualenv(和virtualenvwrapper)隔离python环境的原因。 With virtualenv you can install the version of python you need for you code without clashing with other python versions on your system.
使用virtualenv,您可以安装代码所需的python版本,而不会与系统上的其他python版本冲突。 Python3 comes with virtualenv, but you can read more on virtualenv here and virutalenvwrapper here .
Python3随附virtualenv,但您可以在此处和virutalenvwrapper上阅读有关virtualenv的更多信息 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.