4

I am a beginner to Python and am having great difficulty in running my python googleppengine code locally on my machine.

My code looks as follows:

import json
import urllib
import os
import webapp2
from google.appengine.ext.webapp import template
import datetime
from google.appengine.ext import db


class Events(db.Model):
    venue_name = db.StringProperty()
    address = db.StringProperty()
    id = db.StringProperty()
    venue_id = db.StringProperty()

    # hire_date = db.DateProperty()
    # attended_hr_training = db.BooleanProperty()

class eventSearch(webapp2.RequestHandler):  
    def get(self):
        base_url = 'http://api.eventful.com/json/events/search?app_key=zGtDX6cwQjCRdkf6&l=dublin&?q=music'
        response = urllib.urlopen(base_url)
        html = response.read()
        html = json.loads(html)
        result = html['venues']
        result1 = result['venue']

When I run this code in my cmd prompt with command "python file.py", I receive the following error:

Traceback <most recent call last>:
File "file.py", line 4, in <module>
import webapp2
ImportError: No module named 'webapp2'

I have 1. Created a PythonPath as suggested in How to add to the pythonpath in Windows? within my system variables with directories: C:\Python33\DLLs;C:\Python33\Lib;C:\Python33\Lib\lib2to3;C:\Program Files (x86)\Google\google_appengine;C:\Program Files (x86)\Google\google_appengine\lib;

I have then also added both of the below directories into my "PATH" variable also, as recommended within answer - import webapp2 works on google-app-engine even though I don't have webapp2 installed
C:\Program Files (x86)\Google\google_appengine\;C:\Program Files (x86)\Google\google_appengine\lib

EDIT: After suggestions within the answers provided I too have realized that GAE does not support version 3.3 of Python I was trying to run it with in my previous part of my question. After uninstalling Python33 and installing Python27 instead, changing my system variables to reflect the new Python27, I am still having issues and my code will not upload with the GAE launcher. I receive the following errors within my log-console (GAE Launcher):

2013-04-14 22:59:19 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8001', 'C:\\Users\\Karen\\Desktop\\Development\\projects\\file']"
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in     <module>
    _run_file(__file__, globals())
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 189, in _run_file
    execfile(script_path, globals_)
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 30, in <module>
    from google.appengine.datastore import datastore_stub_util
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\datastore\datastore_stub_util.py", line 45,     in <module>
    from google.appengine.api import api_base_pb
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\api\api_base_pb.py", line 20, in <module>
    from google.net.proto import ProtocolBuffer
  File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 22, in <module>
    import httplib
  File "C:\Python27\lib\httplib.py", line 71, 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.
2013-04-14 22:59:21 (Process exited with code 1)

Thank you for any help that you can provide me.

Ahmed
  • 2,825
  • 1
  • 25
  • 39
Karen
  • 2,469
  • 3
  • 14
  • 10
  • I am also running Windows 7 if this is any addition in providing a solution. – Karen Apr 14 '13 at 12:01
  • I note you are setting up your python path to use Python3.3 This is not a supported runtime for appengine. Use python 2.7. – Tim Hoffman Apr 14 '13 at 12:48
  • Hi @TimHoffman thank you for your replies. I have uninstalled Python3.3 and now have Python2.7 version installed on my machine. I have updated my system variables and I still have no joy. I understand that I cannot utilise the webapp2 module locally on my machine but I am now having such trouble trying to upload the above code using the GAE launcher and I receive multiple errors. I will update my question with the errors in which I have received. – Karen Apr 14 '13 at 22:10
  • If you look at the end of your stacktrace you will see the message `ImportError: Module use of python25.dll conflicts with this version of Python` this is telling you , that you are running python2.7 but for some reason it's trying import 2.5 based DLL's. Your installed environment seems to have a lot of problems. You can use webapp2 locally. THe dev server is running locally. What you can't do is use google modules and not run the dev_appserver. webapp2 is just as lightweight WSGI based framework. – Tim Hoffman Apr 14 '13 at 23:02
  • Ok so do you think I should try and reinstall python2.7 in order to solve this issue or would you say that I should try and search for further configuration settings to get this running? Thank you for your information on webapp2 @Tim I really do appreciate your help. – Karen Apr 14 '13 at 23:22
  • I have now managed to fix this error if anybody is having the same trouble. I changed the preferences within GAE by following these steps: Google App Engine -> Edit (Tab) -> Preferences -> Python Path -> C:\Python27\python.exe and this worked! Solution can be found here: http://forums.udacity.com/questions/6000574/appengine-wants-python-25-installed-on-windows – Karen Apr 15 '13 at 00:27

4 Answers4

3

You should not install webapp2. It is included in the SDK, and is already in the production runtime.

Have a read of Configuring libraries that are part of the appengine environment https://developers.google.com/appengine/docs/python/python25/migrate27#Configuring_Libraries

and here is the list of included 3rd party libs.

https://developers.google.com/appengine/docs/python/tools/libraries27

If you use pip/easy_install for various other libs, you will find on its own that is insufficient. You will need to link or include these libs in your project, manipulate sys.path so they can be found, and make sure these libraries are deployed.

Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29
  • 1
    I am not clear how this solves the import error. Yes, webapp2 is in the runtime - but we are getting an import error like the questioner after upgrading Google App Engine Launcher. The error is occurring in a script that worked fine. Yes - pip easy installs libs - and it makes sense not to do a pip install of something that exists - but what is the advice here for solving the core import webapp2 error? – Praxiteles Jun 02 '16 at 06:10
  • The original question is about a mixed environment of runtimes 2.5 and 2.7 combined with not following the 2.5 -> 2.7 migration path. Are you seeing the same error re: python2.5 dll conflicts ? – Tim Hoffman Jun 02 '16 at 06:39
1

This solved my problem (same problem you got)

First don't try to run from python IDLE run from Google app engine open localhost:port

Open log in GAE if still showing same error try below steps

  1. Check your python version 2.7.X or 3.X
  2. If 3.x install 2.7.8
  3. Then open google app engine console and go to edit > preferences
  4. add your python27 directory (ex:C:\Python27\pythonw.exe) to PythonPath click ok
Niranjan
  • 1,879
  • 2
  • 22
  • 28
0

It looks like appengine/tools/devappserver2/python/sandbox.py is supposed to turn C:\path\to\google_appengine\google into C:\path\to\google_appengine, but there is an extra dirname, so it ends up getting C:\path\to. I'm not sure why it only causes problems in some circumstances.

You can work around the problem by changing:

library_pattern = os.path.join(os.path.dirname(
    os.path.dirname(google.__file__)), _THIRD_PARTY_LIBRARY_FORMAT_STRING)

to:

library_pattern = os.path.join(
    os.path.dirname(google.__file__), _THIRD_PARTY_LIBRARY_FORMAT_STRING)

I found this issue by putting raise Exception(sys.path) in various places in the app engine code and restarting the dev server.

Sean Fujiwara
  • 4,506
  • 22
  • 34
-2

You can install webapp2 by using pip or easy_install. Refer to http://webapp-improved.appspot.com/tutorials/quickstart.nogae.html for quick stark

  • this would make sense if your running webapp2 locally using something other than the appengine dev server. In this case the OP is still using appengine libs and therefore must be running the dev server. – Tim Hoffman Apr 14 '13 at 12:47