문제

I've installed MySQLdb successfully for my system python -- and I've added the library to app.yaml as well, but the dev-appserver does not recognize it. I've followed the tutorial here: https://developers.google.com/appengine/docs/python/cloud-sql/

I downloaded and installed the latest Python mysql from here: http://sourceforge.net/projects/mysql-python/

sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments python setup.py build
sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments python setup.py install

If I run python from the Command Line I can happily import MySQLdb

Here's what I have in app.yaml:

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: "2.6"
- name: MySQLdb
  version: "1.2.4b4"

Here's the exception I get when I try to open a page hosted by my appengine dev server.

ERROR    2014-05-15 20:23:19,480 wsgi.py:262] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 239, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 84, in LoadObject
    obj = __import__(path[0])
  File "xxxx/main.py", line 10, in <module>
    import MySQLdb
ImportError: No module named MySQLdb

Any help would be deeply appreciated -- the tutorial isn't working. Thanks for your generosity and kindness!

-s

도움이 되었습니까?

해결책

The following worked for me. I got the same error from App Engine, but it turned out that the problem was module _mysql wasn't configured properly.

Add this to ~/.bash_profile:

export PATH=$PATH:/usr/local/mysql/bin

Create a symlink to the MySQL lib:

ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

다른 팁

I had the same problem with local development and struggled with it for a while. Eventually, I wrote command line version of all my queries, tested them and then fully deployed the app. It worked from there.

If you find a solution that allows local dev, please post it here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top