繁体   English   中英

在Pyramid Framework中使用Mysql和SqlAlchemy

[英]using Mysql and SqlAlchemy in Pyramid Framework

Pyramid Framework附带了一个使用sqlite的sql炼金术示例教程。 问题是我想使用mysql所以我改变了这个

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

进入这个

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

当我试图跑

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

它给了我以下错误

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

我知道我应该在setup.py中包含我的应用程序的dependecies但是我不知道现在要包括哪些帮助请我的setup.py看起来像这样

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
      """,
      )

尝试将"MySQLdb"添加到需求列表中。 sqlite3很好,因为它带有python(从版本2.5开始),MySQLdb没有,需要单独安装。

更新:

请尝试在需求列表中使用"mysql-python"

有很多非扩展的Python扩展包非官方Windows二进制文件列表对Windows用户非常有用。

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

在ubuntu环境中解决

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

好的我按照本页上的说明解决了我自己的问题http://www.saltycrane.com/blog/2010/02/install-mysqldb-virtualenv-ubuntu-karmic/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM