Getting the error "name 'execfile' is not defined" - google-app-engine

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

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

I've just stumbled upon similar issue myself, In Python 3
Instead of
execfile("./filename")
Use
exec(open("./filename").read())

Related

Running app engine local development server from command prompt (v1.9.36) - Google Cloud complications (No module named portpicker)

I've been running app engine local development server from the command prompt for 3 years without any issues (windows 7, 64bit). I just updated to v1.9.36 (download 960cfe2157c6e984802db4b0224cfe8273d727dc from this page), and now when I run
dev_appserver.py [anything]
I get:
Traceback (most recent call last): File "C:\Program
Files\Google\Cloud
SDK\google-cloud-sdk\platform/google_appengine\dev_appserver.py", line
82, in
_run_file(file, globals()) File "C:\Program Files\Google\Cloud
SDK\google-cloud-sdk\platform/google_appengine\dev_appserver.py", line
78, in _run_file
execfile(_PATHS.script_file(script_name), globals_) File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py",
line 37, in
from google.appengine.tools.devappserver2 import dispatcher File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\devappserver2\dispatcher.py",
line 29, in
from google.appengine.tools.devappserver2 import module File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py",
line 55, in
from google.appengine.tools.devappserver2 import http_runtime File "C:\Program Files
(x86)\Google\google_appengine\google\appengine\tools\devappserver2\http_runtime.py",
line 53, in
import portpicker ImportError: No module named portpicker
The strange thing is that if I use the SDK GUI, and hit the 'Run' button, it launches just fine, no errors. So my guess is that when running from the command line, it's using the version of 'dev_appserver.py' in the Cloud SDK folder, whereas the GUI is running the version in C:\Program Files (x86)\Google\google_appengine\. But my environment variables are:
GAE_SDK_ROOT: C:\Program Files (x86)\Google\google_appengine
PATH: lots of other things, plus C:\Program Files (x86)\Google\google_appengine\
And I dont see any reference to Cloud SDK, so I cant figure why the version in the folder would be run.
There are versions of dev_appserver.py in both C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine and C:\Program Files (x86)\Google\google_appengine
Seems that in combining GAE SDK with Google Cloud, Google has made this more complicated than it used to be..
[UPDATE]
If I run echo %PATH% then among many other things, I see
C:\Program Files\Google\Cloud SDK\google-cloud-sdk..
before
C:\Program Files (x86)\Google\google_appengine\
Which explains why it's running that version. The question now is: why is the former in my PATH if I havent set it in my user PATH variable? Where else is the Windows PATH manipulated? Presumable the Google Cloud SDK installer did this - how do I undo it?
Executing dev_appserver.py [anything] will launch the first dev_appserver.py executable encountered in your executable PATH environment, which appears to be not the one you expect :)
You have 2 options:
update your PATH as needed
execute the desired dev_appserver.py by specifying its full path:
C:\Program Files (x86)\Google\google_appengine\dev_appserver.py [anything]
This answer is somehow related: appcfg.py not working in command line
New answer
I turns out that the Cloud SDK folder was in my system path, which is checked before the user path, so the version of dev_appserver.py in Cloud SDK was being executed, rather than the more up to date version in the app engine folder.
To fix this I simply removed the Cloud SDK from my system path, using the handy app detailed here
Original answer
I worked out that if I rename the Cloud SDK folder in C:\Program Files\Google this fixes it. But that's a hacky fix, and presumably makes the Cloud SDK functionality unavailable (I dont think I currently need it).
So I'd still like a proper answer to this question. It seems that I need a way to control which version of dev_appserver.py gets run, and short of setting my environment variables (which I've already done) I dont know what else to try.
As an alternative to the other answers, if you do not have the old standalone Google App Engine installed and only uses the Google SDK, you can also install portpicker with the following command line (assuming you have pip installed):
pip install portpicker

Can you use the verbatim tag with Django 1.5 on App Engine?

In my app.yaml file I have:
- name: django
version: "1.5"
which I assume means, use Django 1.5. 1.5 includes the verbatim tag, but when I try to use it I get:
TemplateSyntaxError: 'verbatim' is not a valid tag library: Template library verbatim not found, tried google.appengine._internal.django.templatetags.verbatim
Any idea how to enable this feature or is it just not included with app engine, I am using 1.8.9. Thanks!
I don't think it works. When I tried to do this, I got this traceback:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
...
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\_internal\django\template\__init__.py", line 333, in invalid_block_tag
raise self.error(token, "Invalid block tag: '%s'" % command)
TemplateSyntaxError: Invalid block tag: 'verbatim'
Looking at the source C:\Program Files (x86)\Google\google_appengine\google\appengine\_internal\django\__init__.py you can see the version number in the first line:
VERSION = (1, 2, 5, 'final', 0)
This tells me that the appengine is using Django version 1.2.5 for the templating. I do not know if these means you can deploy the app to production and it will somehow use 1.5, but I couldn't get it to work locally. (Note that this was specifying Django 1.5 and Webapp 2.5.2 in my app.yaml using the Google App Engine Launcher 1.9.17)

Does GAE Blob get_serving_url() work on localhost?

I have a python GAE application, with an ndb datastore storing images as a blob property.
I use get_serving_url() function to serve images, and it works properly on the Google App Engine production server ("my-app".appspot.com).
When i try it on localhost, the URL seems to be generated correctly, but if I click on it I receive a blank page.
Is it normal, because GAE does not implement it on localhost, or it's a problem of my development environment? Anyway: is there a way to make it works on localhost? I didn't find any information on the web.
Thank you.
update
Some additional details: all the upload process work correctly, I see the uploaded image in the blobstore viewer, and its url is something like localhost:8000/*blob-key*?display=inline.
When i call get_serving_url() on localhost, i obtain an url like localhost:8080/_ah/img/*blob-key* and it does not work (blank page). I just discovered that on Log Console I receive this message:
ERROR 2013-12-30 11:52:14,299 module.py:665] Request to '/_ah/img/vMDNz9x9ak9VcjBXmfMBcg==' failed
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 661, in _handle_request
return handler.handle(match, environ, wrapped_start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_handler.py", line 59, in handle
return self._wsgi_app(environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\blob_image.py", line 195, in call
return self.serve_image(environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\blob_image.py", line 184, in serve_image
image, mime_type = self._transform_image(blobkey, options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\blob_image.py", line 68, in _transform_image
image = _get_images_stub()._OpenImageData(image_data)
AttributeError: 'ImagesNotImplementedServiceStub' object has no attribute '_OpenImageData'
Anyway, when i deploy on the production server, the get_serving_url() produce something like lh6.ggpht.com/*longer-blob-key* that points on Google servers and works correctly.
You need to install PIL to make it working on your local machine.
Install PIL from https://developers.google.com/appengine/docs/python/images/installingPIL
I solved the issue updating Google App Engine.
Now I have the release 1.9.15 and don't have the problem anymore.

"_run_file" Error with pyramid buildout for Google App Engine in Ubuntu

I built a new project using buildout for Pyramid and GAE under Ubuntu 12.04 (using pyramid_appenegine pcreate template). I started a new VM to ensure no messing with distribute and setuptools in site-packages.
First of all, it results in that setuptools not found error, apparently solved with the patch provided by Tom Willis.
Then, buildout finishes building ok, but starting the develop site results in that error:
funky#funkydesktop:~/dev/gae1$ bin/devappserver parts/gae1
Traceback (most recent call last):
File "bin/devappserver", line 25, in <module>
sys.exit(dev_appserver._run_file('/home/funky/dev/gae1/parts/google_appengine/dev_appserver.py', locals()))
AttributeError: 'module' object has no attribute '_run_file'
Any hints to solve that one, or the whole process of building and starting the application?
I finally solved the problem by changing ae-sdk-version to 1.8.0.
Open buildout.cfg and change the line
ae-sdk-version=1.7.5
to:
ae-sdk-version=1.8.0
Or either you could see what happens with pyramid_appengine version (I got 0.8.1 instead of 0.8.2-a2 which is the current one in pypi.python.org). This is the package that holds the template.

ImportError while running Google App Engine test project

I am new to Google App Engine and so, I just followed the procedure to test an application which just prints "hello world".
(followed according to Google App Engine Documentation)
The project folder name is "GoogleApp"
This is my Python file:
File Name : sayHello.py
#!/usr/bin/env python
def main():
print "hello"
pass
if __name__ == '__main__':
main()
This the yaml file
File Name : app.yaml
application: GoogleApp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: sayHello.py
When ever I just run the project in Google App Engine Launcher, this is the log error I am getting
2012-04-19 10:52:23 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8080', 'D:\\Code\\Projects\\IRCmathBot\\GoogleApp']"
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 125, in <module>
run_file(__file__, globals())
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 121, in run_file
execfile(script_path, globals_)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_main.py", line 157, in <module>
from google.appengine.tools import appcfg
File "C:\Program Files\Google\google_appengine\google\appengine\tools\appcfg.py", line 41, in <module>
import mimetypes
File "C:\Python27\lib\mimetypes.py", line 29, in <module>
import urllib
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
2012-04-19 10:52:25 (Process exited with code 1)
Actually, I use Python 2.7. The above log says that python25.dll conflicts with version of python.
I don't know what exactly it means but I could interpret that
It should either support only python 2.5 or
It I should have used python 2.5 code.
as the 2nd isn't possible and Google supports 2.7, I don't know what is this error.
Try to figure out myself but couldn't succeed.
I had a very similar problem (while running the tutorial code), and solved it by checking my PythonPath system environment variable.
For me, OpenCV edited the PythonPath variable to point to its own directory structure instead of the base Python installation itself.
You can edit the environment variables by opening up the 'Advanced System Properties' window and clicking on the 'Environment Variables' button. The 'PythonPath' variable under 'System Variables'. At the minimum, it should include the path of your python executable, such as 'C:\Python27\'.
Have you tried in command-line? Forget the launcher.
I had same problem! I re-installed Python several times, changed versions. It was hilarious.
With version 2.5 launcher can start the server, but the application doesn't work, but I can upload it online through launcher.
With Python ver. 2.7, launcher displays same problems you're dealing with. I also can't get the server started locally. But command-line works well, both starting the server locally and uploading online.
So I'll stick with version 2.7. Hope it helps, let me know..
You have threadsafe enabled, so you should use WSGI handlers. That could be the problem. I would replace your code with the following:
File: helloworld.py
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, WebApp World!')
app = webapp2.WSGIApplication([('/', MainPage)])
File: app.yaml
application: GoogleApp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
If using Python2.7 on Google AppEngine, refer to this official documentation to create your first "Hello World" Application.
I fixed this after 3 hrs of effort. Reinstall cannot solve my problem, messing around the user/system environment variable also not work.
Follow this step work:
Open Google Drive Perference, turn off auto run after win start up
turn off Google Drive
or simply uninstall google drive (Google Drive seems using Python 2.5 _socket library
uninstall python and GAE
reboot
install python27 and GAE
Most importantly, specify a new path, do not use the default c:\python27 again (I changed it to c:\mypython27. same as GAE, use a new path.
Then it works again.
Something's seriously broken with your Python 2.7 installation - parts of it are referencing Python 2.5 libraries. You should uninstall all versions of Python on your machine, and reinstall the version(s) you need.
I guess you've added the GAE path into the environment variable PATH? Just remove it.
I had exactly the same problem with you, it seems to me that Python 2.7 will try to use an incorrect _socket.pyd lib under GAE path, removing GAE path from PATH will fix this.
It needs no extra coding, just a tiny configuration of your win OS.
Since my OS language is Chinese, names of icons/links below are translated from Chinese by myself, which i cannot guarantee to be correct :(
Right click on the "Computer" icon, choose 'Properties', you'll see the system panel showing some basic system information;
Click on the "Advanced System Settings" link, you'll see the system property panel containing several tabs;
Choose the "Advanced" tab, there should be a button named "Environment variables" on the bottom, click on it then you can see a dialog displaying all environment variables of your system;
Find and edit the variable named "PATH" or "Path" (case insensible): if its value contains a path to your GAE, then remove the GAE path.
For me it was that I did set the System Variable PYTHONPATH to '.'. Deleting the variable did the job!
I set PYTHON_PATH to
"C:\Program Files\Google\google_appengine;C:\Program
Files\Google\google_appengine\lib\antlr3;C:\Program
Files\Google\google_appengine\lib\django_0_96;C:\Program
Files\Google\google_appengine\lib\fancy_urllib;C:\Program
Files\Google\google_appengine\lib\graphy;C:\Program
Files\Google\google_appengine\lib\ipaddr;C:\Program
Files\Google\google_appengine\lib\simplejson;C:\Program
Files\Google\google_appengine\lib\webob;C:\Program
Files\Google\google_appengine\lib\yaml\lib"
but then I realize that django 0.96 require python 2.5, so use django 1.4, and it works fine.
"C:\Program Files\Google\google_appengine;C:\Program
Files\Google\google_appengine\lib\antlr3;C:\Program
Files\Google\google_appengine\lib\django-1.4;C:\Program
Files\Google\google_appengine\lib\fancy_urllib;C:\Program
Files\Google\google_appengine\lib\graphy;C:\Program
Files\Google\google_appengine\lib\ipaddr;C:\Program
Files\Google\google_appengine\lib\simplejson;C:\Program
Files\Google\google_appengine\lib\webob;C:\Program
Files\Google\google_appengine\lib\yaml\lib"
If you have same problem as above, just check PATH, PYTHON_PATH to see whether mismatch version between library and python. Hope this help.
Some programs may modify the PYTHONPATH environment variable. If you check it's value (System -> Environment variables) and ensure it is set to the correct python 2.7 path (default C:\Python27) then this should fix the issue. In my case something had set it to my google appengine path.
ImportError: Module use of python25.dll conflicts with this version of Python.
The problem is that python25.dll conflicts with your Python 2.7 installation. This python25.dll comes from the greatly outdated Google App Engine Launcher for Windows and is located in C:\Program Files\Google\google_appengine\launcher
It is not a problem of your Python 2.7 install - it is a problem of Launcher, who injects its own Python path into app environment. To test that, add the following lines at the top of google_appengine/dev_appserver.py after first imports:
from pprint import pprint
pprint(sys.path)
Then re-run you app to get fresh log and see for yourself:
...
'C:\\OpenCV2.3\\opencv\\build\\python\\2.7',
'C:\\Google\\google_appengine\\launcher',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\DLLs',
...
I got the launcher from Python .msi SDK 1.8.8, and it is of course suxx that Google still ships several versions of SDK with broken GUI tool. To fix that, add the following after first imports in dev_appserver.py:
# --- Repair sys.path after broken GAE Windows Launcher
# see http://stackoverflow.com/questions/10222342/
ROOT = os.path.abspath(os.path.dirname(__file__))
LAUNCHPATH = os.path.join(ROOT, 'launcher')
if LAUNCHPATH in sys.path:
sys.stderr.write('[BUG] GAE Windows Launcher detected. Fixing..\n')
sys.path.remove(LAUNCHPATH)
# /--
Unfortunately, you'll need to repeat the procedure when new version of GAE comes out. There is an issue #8568 on AppEngine tracker that you can star and comment to make it fixed someday.
Do you have a PYTHONPATH variable in Environment Variables? delete it and restart the Google App Engine Launcher,it will work!

Resources