如何让Python知道寻找.py文件的路径?

发布于 2024-10-15 02:03:22 字数 408 浏览 1 评论 0原文

今天刚开始尝试学习Python和Django。按照他们的文档,我能够安装 Python 和 Django 并让它们启动并运行。顺便说一句,我在 Windows 7 上运行 Apache 2.2。

我到达了官方教程中的部分,告诉我 cd 到我想要的项目目录并运行此命令

django-admin.py startproject mysite

但是我不能只运行该命令是。我需要像这样运行它

python c:\Python27\Scripts\django-admin.py startproject mysite

我应该像这样输入整个内容吗?或者是否有一些我错过的设置可以让我运行 .py 文件而不需要前面的 python C:\Python27\Scripts\ 部分?

Just started trying to learn Python and Django today. Following their documentations I was able to install Python and Django and got them up and running. I'm running Apache 2.2 on on Windows 7 by the way.

I got to the part in the official tutorial that tells me to cd to the directory I want for my project and run this command

django-admin.py startproject mysite

However I can't just run that command as is. I need to run it like this

python c:\Python27\Scripts\django-admin.py startproject mysite

Am I suppose to type out the whole thing like this? Or is there some settings I miss that will let me run the .py file without the python C:\Python27\Scripts\ part in front?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗恋未遂 2024-10-22 02:03:22

如果您只想输入 django-admin.py,则需要设置两件事:

  • 包含它的目录需要位于您的 PATH 中。
  • 您需要确保 .py 扩展名与 Python 解释器关联。这通常在安装 Python 期间完成。

如何在 Windows 7 上设置 PATH:http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

如何确保 .py 与 Python 关联: http://docs.python.org/faq/windows .html

If you want to just be able to type django-admin.py, two things need to be set up:

  • The directory containing it needs to be in your PATH.
  • You need to make sure that the .py extension is associated with the Python interpreter. This is normally done during the installation of Python.

How to set the PATH on Windows 7: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

How to make sure .py is associated with Python: http://docs.python.org/faq/windows.html

音栖息无 2024-10-22 02:03:22

尝试运行:

python django-admin.py startproject mysite

如果这不起作用,请尝试将 C:\Python27\ 添加到命令搜索路径

Try running:

python django-admin.py startproject mysite

If that don't work, try adding C:\Python27\ to the command search path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文