1

I am using python 3.4 on Lubuntu, which has by default both python2.7 and python3.4

I installed MySQLdb and am trying to use it in python3.4 using pip3

But merely import MySQLdb results in this error

Traceback (most recent call last):
  File "/home/tahseen/workspace/stockproject/test.py", line 18, in <module>
    import MySQLdb as mysql
  File "/usr/local/lib/python3.4/dist-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql

ImportError: /usr/local/lib/python3.4/dist-packages/_mysql.so: undefined symbol: _Py_ZeroStruct`

Surprisingly when I use python2.7, this error does not come up

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Tahseen
  • 111
  • 1
  • 2
  • 11

1 Answers1

3

Quoting another post:

"MySQLdb does not support Python 3 but it is not the only MySQL driver for Python.

You can try using PyMySQL. It is a pure python MySQL driver, which means it is slower, but it does not require a compiled C component or MySQL libraries and header files to be installed on client machines. The latest version on pypi, 0.6.2, has Python 3.4 support.

Another option is simply to use another database system like PostgreSQL."

link: Python 3.4.0 with MySQL database

ps. if you chek at https://pypi.python.org/pypi/MySQL-python/1.2.3 you'll be able to read that Python 3.0 will be supported in a future release

Community
  • 1
  • 1
Viglia
  • 71
  • 6
  • 3
    `MySQL-python` has been claiming it will support Py3 in a future release for years without doing so. If you want an API equivalent replacement for Py3, [take a look at `mysqlclient`](https://pypi.python.org/pypi/mysqlclient), which forked `MySQL-python`, adding support for Py3.3+ (while still supporting 2.7 as well, so you can use it as a replacement for `MySQL-python` on both Py2 and Py3). Unlike `PyMySQL` (and like `MySQL-python`), it's a Python extension module, so the performance is equivalent (read: faster, and potentially _much_ faster for threading since it can release the GIL). – ShadowRanger Nov 10 '16 at 17:07
  • 1
    It's 2020 and it still doesn't support python3. Apparently the project has been abandoned _many_ years ago. – nnsense Feb 28 '20 at 11:19