SQLAlchemy导入错误:import _mysql

时间:2014-08-17 01:11:49

标签: python mysql python-2.7 sqlalchemy pydev

我是Python和SQLAlchemy的新手,我尝试使用它们一点点,但每当我运行测试时它会给我以下错误:

Traceback (most recent call last):
  File "/home/zakaria/workspace-python/Jerreb/essai/tejriba.py", line 11, in <module>
    engine = create_engine("mysql://root:root@localhost/python")
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/engine/__init__.py", line 346, in create_engine
    return strategy.create(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/engine/strategies.py", line 74, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-i686.egg/sqlalchemy/connectors/mysqldb.py", line 64, in dbapi
    return __import__('MySQLdb')
  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-i686.egg/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: /usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-i686.egg/_mysql.so: undefined symbol: _Py_ZeroStruct

我正在与PyDev合作。

这是项目架构:

Project Architecture

这些是我导入的库:

Project Libs

问题是什么,我该如何解决?

谢谢!

1 个答案:

答案 0 :(得分:1)

当我收到此消息时,事实证明,在我不知道的情况下,代码是在Python 3解释器而不是Python 2中运行的。(这是因为我安装了Ubuntu&#39; s {{1}对于另一个项目。)libapache2-mod-wsgi-py3还不支持Python 3.:&#39;(

我不知道WSGI是否涉及到您,但请确保您没有运行Python 3.