Django错误加载MySQLdb模块未定义的符号:_ZTVN10__cxxabiv117__class_type_infoE

时间:2016-06-15 09:25:46

标签: python mysql django python-2.7

我正在使用centos 6.5 / Python2.7.10 / Django / MySQL,当我尝试运行时出现以下错误:

python manage.py check

错误是:

Traceback (most recent call last):
  File "../manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/ez_sh/site/ettwit/kindergarten/models.py", line 14, in <module>
    class Kindergarten(models.Model):
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/base.py", line 307, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/python2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/python2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: /usr/local/python2.7/lib/python2.7/site-packages/_mysql.so: undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE

我使用了pip install mysqlclient

1 个答案:

答案 0 :(得分:0)

我几乎整整一天都遇到了这个问题,现在我解决了这个问题。 首先,不要通过pip install mysqlclient安装mysqlclient,你应该从源代码安装(下载here)。

然后:

tar -zxvf mysqlclient-1.3.7.tar.gz
cd mysqlclient-1.3.7
python setup.py build

现在,最重要的一步,使用g++重新编译_mysql.so

g++ -pthread -shared build/temp.linux-x86_64-2.7/_mysql.o \
    -L/usr/lib64 -lmysqlclient_r -lpthread -lm -lrt -ldl -o build/linux-x86_64-2.7/_mysql.so

最后:

python setup.py install

并检查是否还有问题,我的运行正常:

python -c "import MySQLdb"
or python manage.py check

说实话,我不知道错误出现的原因。如果您有任何想法,请告诉我。