dev_appserver.py 打开文本文件,但不部署

7 投票
3 回答
3253 浏览
提问于 2025-04-18 11:57

在我的另一台电脑上运行得很好,但在设置好Google App Engine并创建了main.py和app.yaml文件后,我在Windows命令提示符下运行dev_appserver.py app.yaml,结果不是把应用部署到localhost:8080,而是直接打开了这个文本文件,内容我就简化一下:

#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Convenience wrapper for starting an appengine tool."""

import os
import sys

sys_path = sys.path
try:
  sys.path = [os.path.dirname(__file__)] + sys.path

  import wrapper_util

finally:
  sys.path = sys_path

wrapper_util.reject_old_python_versions((2, 7))

_DIR_PATH = wrapper_util.get_dir_path(__file__, os.path.join('lib', 'ipaddr'))
_PATHS = wrapper_util.Paths(_DIR_PATH)

等等等等。

这是怎么回事呢?所有设置和我的另一台电脑完全一样,应该可以正常工作的。

3 个回答

0

你应该把项目目录提供给 dev_appserver.py,而不是 app.yaml。想了解更多信息,可以参考这个 GAE Python Hello World 示例

假设你的项目目录是:

"/home/rami/GAEproejcts/myfirstproject"

而你的 dev_appserver.py 文件在:

"/home/rami/GAEinstalldirectory/"

那么你只需要运行:

$ /home/rami/GAEinstalldirectory/dev_appserver.py /home/rami/GAEproejcts/myfirstproject

这样就可以了。

2

这个电脑上安装了Python吗?你看到的情况是,Windows系统不知道“.py”文件是和Python关联的。

在64位Windows上安装SetupTools可能会提供一些有用的信息。

15

问题解决了!原来所有的 .py 文件都是设置成用 idle.bat 打开的,所以我需要去 控制面板\程序\默认程序\设置文件关联,把 .py 文件的打开方式改成 python.exe。现在一切都运行得非常顺利。

撰写回答