MySQLdb与python3.4

2024-06-28 18:47:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Lubuntu上使用python3.4,默认情况下python2.7和python3.4都有

我安装了MySQLdb并试图在python3.4中使用pip3

但是仅仅导入MySQLdb就会导致这个错误

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`

令人惊讶的是,当我使用python2.7时,并没有出现这个错误


Tags: inpyimportlibpackagesusrlocaldist
1条回答
网友
1楼 · 发布于 2024-06-28 18:47:14

引用另一篇文章:

"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."

链接:Python 3.4.0 with MySQL database

另外,如果您在https://pypi.python.org/pypi/MySQL-python/1.2.3进行检查,您将能够阅读到Python 3.0将在将来的版本中得到支持

相关问题 更多 >