appcfg.py无法在命令行中运行

时间:2015-10-14 16:49:54

标签: python-2.7 google-app-engine appcfg

我只是在理解为什么这个命令时遇到了一些麻烦:

>appcfg.py -A adept-box-109804 update app.yaml
由“尝试Google App Engine Now”页面提供的

不起作用。我已下载App Engine SDK for Python,并将Path设置为指向appcfg.py的位置,但在我的项目根目录中运行appcfg.py在命令行中不起作用。我要么导航到包含appcfg.py的文件夹并执行

>python appcfg.py help

或做

>python "C:\Program Files (x86)\Google\google_appengine\appcfg.py" help

从任何地方获取命令。我使用后一种方法来部署我的测试应用程序,但只是想知道是否有人可以解释为什么简单的Google教程给出的命令没有做任何事情。我还检查了确保.py文件是使用Python 2.7解释器自动打开的,这样只需键入

就可以在命令行中执行文件hello.py
>hello.py

它将输出其print语句。另一方面,使用appcfg.py以类似的方式提供相同的输出,无论参数如何(请注意我截断输出,但请放心,无论参数如何,它们都是相同的:

C:\>appcfg.py help backends
Usage: appcfg.py [options] <action>

Action must be one of:
  backends: Perform a backend action.
  backends configure: Reconfigure a backend without stopping it.
  backends delete: Delete a backend.
  backends list: List all backends configured for the app.
  backends rollback: Roll back an update of a backend.
  backends start: Start a backend.
  backends stop: Stop a backend.
  backends update: Update one or more backends.
  create_bulkloader_config: Create a bulkloader.yaml from a running application.
  cron_info: Display information about cron jobs.
  delete_version: Delete the specified version for an app.
  download_app: Download a previously-uploaded app.
  download_data: Download entities from datastore.
  help: Print help for a specific action.
  list_versions: List all uploaded versions for an app.
  request_logs: Write request logs in Apache common log format.
  resource_limits_info: Get the resource limits.
  rollback: Rollback an in-progress update.
  set_default_version: Set the default (serving) version.
  start_module_version: Start a module version.
  stop_module_version: Stop a module version.
  update: Create or update an app version.
  update_cron: Update application cron definitions.
  update_dispatch: Update application dispatch definitions.
  update_dos: Update application dos definitions.
  update_indexes: Update application indexes.
  update_queues: Update application task queue definitions.
  upload_data: Upload data records to datastore.
  vacuum_indexes: Delete unused indexes from application.
Use 'help <action>' for a detailed description.

C:\>appcfg.py help update
Usage: appcfg.py [options] <action>

Action must be one of:
  backends: Perform a backend action.
  backends configure: Reconfigure a backend without stopping it.
  backends delete: Delete a backend.
  backends list: List all backends configured for the app.
  backends rollback: Roll back an update of a backend.
  backends start: Start a backend.
  backends stop: Stop a backend.
  backends update: Update one or more backends.
  create_bulkloader_config: Create a bulkloader.yaml from a running application.
  cron_info: Display information about cron jobs.
  delete_version: Delete the specified version for an app.
  download_app: Download a previously-uploaded app.
  download_data: Download entities from datastore.
  help: Print help for a specific action.
  list_versions: List all uploaded versions for an app.
  request_logs: Write request logs in Apache common log format.
  resource_limits_info: Get the resource limits.
  rollback: Rollback an in-progress update.
  set_default_version: Set the default (serving) version.
  start_module_version: Start a module version.
  stop_module_version: Stop a module version.
  update: Create or update an app version.
  update_cron: Update application cron definitions.
  update_dispatch: Update application dispatch definitions.
  update_dos: Update application dos definitions.
  update_indexes: Update application indexes.
  update_queues: Update application task queue definitions.
  upload_data: Upload data records to datastore.
  vacuum_indexes: Delete unused indexes from application.
Use 'help <action>' for a detailed description.

3 个答案:

答案 0 :(得分:6)

我终于找到了真正的原因,这不是AppEngine SDK的错误。相反,它是我的Python解释器,因为我注意到它不接受任何.py文件的参数。它原来是一个注册表错​​误,位于 [HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] ,我必须将值从"C:\Python27\python.exe" "%1"更改为 "C:\Python27\python.exe" "%1" %*

这是怎么发生的,无论是Python 2.7安装程序,还是AppEngine SDK,我都不确定。

答案 1 :(得分:3)

您的混淆可能源于混合了两种可能的调用样式:

  1. python appcfg.py ...
  2. appcfg.py ...
  3. 第一个不能利用appcfg.py的位置在路径中的事实,它只是python可执行文件的一个参数,它无法找到appcfg.py 1}}文件,除非:

    • 它在当前目录中找到它
    • 使用完整路径或相对于调用appcfg.py的当前工作目录的路径指定python文件

    这就是你的第二和第三个命令无法正常工作的原因。如果appcfg.py的位置在路径中,则使用第二个调用样式应该有效 - 就像上次命令调用一样。

    要记住的关键点:路径配置仅适用于命令可执行文件,而不适用于其参数(每个可执行文件可以按照自己的意愿处理BTW,某些可执行文件可能将参数与路径配置相结合以获取文件的位置。

    类似地appcfg.py本身(一旦使用2种调用样式中的任何一种成功调用),就需要能够找到指定为参数的app.yaml文件。除非:

    ,否则不能这样做
    • 它在当前目录中找到它
    • 使用完整路径或相对于调用app.yaml的当前工作目录的路径指定appcfg.py文件(或其目录)

    我怀疑appcfg.py无法找到您的app.yaml文件可能是您提到的第一个命令不起作用的原因。如果没有,您应该提供有关失败的详细信息。

    关于为什么最后一个命令的输出无论参数如何都是相同的,我不确定,它可能是SDK的Windows版本中的错误。在linux中,输出是不同的:

    > appcfg.py help backends
    Usage: appcfg.py [options] backends <directory> <action>
    
    Perform a backend action.
    
    The 'backends' command will perform a backends action.
    
    Options:
      -h, --help            Show the help message and exit.
      -q, --quiet           Print errors only.
      -v, --verbose         Print info level logs.
      --noisy               Print all logs.
      -s SERVER, --server=SERVER
                            The App Engine server.
      -e EMAIL, --email=EMAIL
                            The username to use. Will prompt if omitted.
      -H HOST, --host=HOST  Overrides the Host header sent with all RPCs.
      --no_cookies          Do not save authentication cookies to local disk.
      --skip_sdk_update_check
                            Do not check for SDK updates.
      -A APP_ID, --application=APP_ID
                            Set the application, overriding the application value
                            from app.yaml file.
      -M MODULE, --module=MODULE
                            Set the module, overriding the module value from
                            app.yaml.
      -V VERSION, --version=VERSION
                            Set the (major) version, overriding the version value
                            from app.yaml file.
      -r RUNTIME, --runtime=RUNTIME
                            Override runtime from app.yaml file.
      -E NAME:VALUE, --env_variable=NAME:VALUE
                            Set an environment variable, potentially overriding an
                            env_variable value from app.yaml file (flag may be
                            repeated to set multiple variables).
      -R, --allow_any_runtime
                            Do not validate the runtime in app.yaml
      --oauth2              Ignored (OAuth2 is the default).
      --oauth2_refresh_token=OAUTH2_REFRESH_TOKEN
                            An existing OAuth2 refresh token to use. Will not
                            attempt interactive OAuth approval.
      --oauth2_access_token=OAUTH2_ACCESS_TOKEN
                            An existing OAuth2 access token to use. Will not
                            attempt interactive OAuth approval.
      --authenticate_service_account
                            Authenticate using the default service account for the
                            Google Compute Engine VM in which appcfg is being
                            called
      --noauth_local_webserver
                            Do not run a local web server to handle redirects
                            during OAuth authorization.
    

答案 2 :(得分:0)

我遇到了这个问题,并且深化了与应用引擎python版本不同的局部变量python版本。 因此,解决方案是在脚本之前添加当前python版本位置:

C:\Python27\python.exe "C:\Program Files (x86)\Google\google_appengine\appcfg.py"

它恢复正常工作。