简体   繁体   中英

“Import Error: dynamic module does not define init function (init_mysql)” importing MySQLdb on OS X

I installed the mysqldb for python on mac os x, but it gives me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.6-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)

How can I solve this issue?

This is most likely due to a mismatch in architectures between the Python you are using, the MySQLdb adapter you installed, and the MySQL client libraries you have installed. They all need to have at least one common architecture and execute in that architecture. You may have a 32-bit-only Python and a 64-bit-only MySQL client library or vice versa. Make sure they match.

Unless you need the Python you are using, I strongly suggest installing a complete solution from a third-party package manager. For example, if you install the MacPorts base, you can then install everything you need (Python 2.7, MySQLdb, MySQL client library, and all dependencies) with one command:

sudo port install py27-mysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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