获取到错误信息:”name ‘execfile’ is not defined”

huangapple go评论89阅读模式
英文:

Getting the error "name 'execfile' is not defined"

问题

我已经按照https://cloud.google.com/appengine/docs/go/#creating_a_simple_http_handler上的步骤进行了操作,但在尝试运行helloworld应用程序时遇到了问题。

我收到以下错误消息:

C:\Users\kirill\Desktop\go_appengine>goapp serve myapp

Traceback (most recent call last):
File "C:\Users\kirill\Desktop\go_appengine\dev_appserver.py", line 83, in
_run_file(file, globals())
File "C:\Users\kirill\Desktop\go_appengine\dev_appserver.py", line 79, in _run_file
execfile(PATHS.script_file(script_name), globals)
NameError: name 'execfile' is not defined
error while running dev_appserver.py: exit status 1

英文:

获取到错误信息:”name ‘execfile’ is not defined”

I have followed all the steps on https://cloud.google.com/appengine/docs/go/#creating_a_simple_http_handler on how to get started with Go, but I am stuck on an issue while trying to run the helloworld app.

I get the following error:

C:\Users\kirill\Desktop\go_appengine>goapp serve myapp

Traceback (most recent call last):
  File "C:\Users\kirill\Desktop\go_appengine\\dev_appserver.py", line 83, in <module>
    _run_file(__file__, globals())
  File "C:\Users\kirill\Desktop\go_appengine\\dev_appserver.py", line 79, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
NameError: name 'execfile' is not defined
error while running dev_appserver.py: exit status 1

答案1

得分: 4

Go AppEngine SDK 需要使用 Python 2.7(不能使用 Python 3.x)。看起来你的 SDK 正在使用 Python 3.x,或者你根本没有安装 Python(在你的 PATH 中)。

首先确保将 Python 2.7 添加到你的 PATH 中,这样 goapp 就会使用它。你可以在这里获取它:Python 2.7.11。对于 Go AppEngine SDK,一个小巧、便携的 Python 也足够了,你可以在这里获取:Single-File Stand-alone Python 2.7.9 for Windows。下载 pyexe-2.7.9.10.zip 并解压缩。它只是一个 10 MB 的单个文件,将其重命名为 python.exe 并将其添加到你的 PATH 中。

此外,进一步看来,你正在从错误的文件夹中启动你的 Hello World 应用程序:你正在 SDK 的文件夹中,而你想要指定你的应用程序位于 SDK 内的 myapp 子文件夹中,这是不太可能的。

导航到包含你的应用程序的文件夹中(app.yaml 必须在那里)。在该文件夹中执行以下命令:

goapp serve

这将在当前文件夹中启动应用程序。为了使其工作,goapp 命令(Windows 上的 goapp.bat)必须添加到你的 PATH 中。

如果你不能或不想将你的 go_appengine 文件夹添加到你的 PATH 中,仍然导航到包含你想要启动的应用程序的文件夹,但提供 goapp 的路径,例如:

C:\Users\kirill\Desktop\go_appengine\goapp serve
英文:

Go AppEngine SDK requires Python 2.7 (Python 3.x cannot be used). It looks to me your SDK is using Python 3.X or you don't have Python at all (in your PATH).

First make sure Python 2.7 is added to your PATH so that will be used by goapp. You can get it here: Python 2.7.11. For the Go AppEngine SDK a small, portable Python is also enough, you can get it from here: Single-File Stand-alone Python 2.7.9 for Windows. Download pyexe-2.7.9.10.zip and extract it. It's just a 10 MB single file, rename it to python.exe and add it to your PATH.

Also going further, it looks to me you are starting your Hello world app from the wrong folder: you are standing in the SDK's folder, and you want to start it specifying that your app is in the myapp subfolder inside your SDK, which is unlikely.

Navigate to the folder where you app is (app.yaml must be there). In that folder execute the command

goapp serve

This will start the app being in the current folder. For this to work, the goapp command (goapp.bat on windows) must be added to your PATH.

If you can't or don't want to add your go_appengine folder to your PATH, still navigate to the folder containing the app you want to start, but provide the path for goapp, e.g.

C:\Users\kirill\Desktop\go_appengine\goapp serve

答案2

得分: 0

我刚刚遇到了类似的问题,使用Python 3时,可以将以下代码:

execfile("./filename")

替换为:

exec(open("./filename").read())
英文:

I've just stumbled upon similar issue myself, In Python 3
Instead of

execfile("./filename") 

Use

exec(open("./filename").read())

huangapple
  • 本文由 发表于 2016年2月25日 14:02:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/35619557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定