0

I'm working on centos 6.5/Python2.7.10/Django/MySQL, I get the following error when I try to run:

python manage.py check

The error is:

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

I have used pip install mysqlclient.

zondo
  • 19,901
  • 8
  • 44
  • 83

1 Answers1

0

I got stuck with this problem for almost a whole day, now I solved the problem. First, do not install mysqlclient through pip install mysqlclient, you should install from source(download here).

Then:

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

now, the most important step, use g++ recompiling _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

Finally:

python setup.py install

and check if there is also a problem, and mine is running fine:

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

To tell the truth, I don't know why the error comes out. If you have any ideas, please tell me.

  • It's probably the easiest way to follow the path of installing everything on RHEL (Fedora,RedHat,CentOS) using yum and rpm rather than building from source, so following the standard path is 1. Instaling the "Development Tools" icluding g++ and other libs, 2. Installing MySQL 5.5 or 5.6 using yum and lastly installing python-devel and python-mysql related modules using yum - it's obvious that as you were building from source some libraries are still missing so doing it through yum on RHEL is safer - building from source involves being aware of the necessary flags being active. – dmitryro Jun 16 '16 at 03:23
  • To install Development Tools use yum groupinstall -y 'development tools' – dmitryro Jun 16 '16 at 03:24
  • http://stackoverflow.com/questions/23541205/cant-install-python-dev-on-centos-6-5 - with the amendments specific to your version of python and centos – dmitryro Jun 16 '16 at 03:34