using Mysql and SqlAlchemy in Pyramid Framework

戏子无情 提交于 2019-12-07 19:01:52

问题


Pyramid Framework comes with a sample tutorial of sql alchemy that uses sqlite. The problem is that i want to use mysql so i change this

sqlalchemy.url = sqlite:///%(here)s/tutorial.db

Into this

sqlalchemy.url = mysql://root:22password@localhost/alchemy

when i try to run

../bin/pserve development.ini --reload

It gives me the following error

 File "build/bdist.linux-i686/egg/sqlalchemy/connectors/mysqldb.py", line 52, in dbapi
ImportError: No module named MySQLdb

I understand that i should include the dependecies of my app in setup.py but i don't know what to include right now some help please my setup.py looks like this

import os
import sys

from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.txt')).read()
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()

requires = [
    'pyramid',
    'SQLAlchemy',
    'transaction',
    'pyramid_tm',
    'pyramid_debugtoolbar',
    'zope.sqlalchemy',
    ]

if sys.version_info[:3] < (2,5,0):
    requires.append('pysqlite')

setup(name='tutorial',
      version='0.0',
      description='tutorial',
      long_description=README + '\n\n' +  CHANGES,
      classifiers=[
        "Programming Language :: Python",
        "Framework :: Pylons",
        "Topic :: Internet :: WWW/HTTP",
        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
        ],
      author='',
      author_email='',
      url='',
      keywords='web wsgi bfg pylons pyramid',
      packages=find_packages(),
      include_package_data=True,
      zip_safe=False,
      test_suite='tutorial',
      install_requires = requires,
      entry_points = """\
      [paste.app_factory]
      main = tutorial:main
      [console_scripts]
      populate_tutorial = tutorial.scripts.populate:main
      """,
      )

回答1:


Try adding "MySQLdb" to the requires list. It was fine with sqlite3 as that comes with python (as of version 2.5), MySQLdb doesn't and needs to be installed separately.

UPDATE:

Try "mysql-python" in the requires list instead.




回答2:


Okay i Solved my own question by following the directions on this page http://www.saltycrane.com/blog/2010/02/install-mysqldb-virtualenv-ubuntu-karmic/




回答3:


There is the huge list of Unofficial Windows Binaries for Python Extension Packages which are extremely useful for Windows users.

http://www.lfd.uci.edu/~gohlke/pythonlibs/




回答4:


Solved in ubuntu environment

  1. sudo apt-get build-dep python-mysqldb
  2. source /bin/active && pip install MySQL-python


来源:https://stackoverflow.com/questions/8773380/using-mysql-and-sqlalchemy-in-pyramid-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!