MySQLdb 与 python3.4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25924931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:49:36  来源:igfitidea点击:

MySQLdb with python3.4

pythonmysql-pythonpython-3.4

提问by Tahseen

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

我在 Lubuntu 上使用 python 3.4,它默认有 python2.7 和 python3.4

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

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

But merely import MySQLdb results in this error

但仅导入 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`

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

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

回答by Viglia

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

“MySQLdb 不支持 Python 3,但它不是 Python 的唯一 MySQL 驱动程序。

您可以尝试使用 PyMySQL。它是一个纯 python MySQL 驱动程序,这意味着它更慢,但它不需要在客户端机器上安装编译的 C 组件或 MySQL 库和头文件。pypi 上的最新版本 0.6.2 支持 Python 3.4。

另一种选择是简单地使用另一个数据库系统,如 PostgreSQL。”

link: Python 3.4.0 with MySQL database

链接:带有 MySQL 数据库的 Python 3.4.0

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

附:如果您查看https://pypi.python.org/pypi/MySQL-python/1.2.3,您将能够了解到 Python 3.0 将在未来版本中得到支持