How to Access MySQL with Python Version 3.4

http://askubuntu.com/questions/630728/how-to-access-mysql-with-python-version-3-4

How to Access MySQL with Python Version 3.4


up vote0down votefavorite

Python comes in two versions: Python 2.7.6 which has now been superseded by Python 3.4.0. The critical line in Python to access MySQL is "import MySQLdb"

Thanks to a response from StackOverFlow, I realized that I was unintentionally accessing MySQL through Python version 2.7.6. Apparently, "MySQLdb" is not compatible with Python version 3.4.0.

Searching the internet has disclosed alternatives for connecting Python to MySql, however, many of the suggestions do not disclose whether the offered solutions would actually work with Python version 3.4.0.

This StackOverFlow Post listed some possible solutions. Python 3.4.0 with MySQL database. I installed mysqlclient 1.3.6, I also ran "sudo pip install PyMySQL" with out error.

However, upon entering python with "python3"; I still received the error message "ImportError: No module named ‘MySQLdb‘" after typing in: "import MySQLdb". So something was still wrong.

As an FYI MySQL evidently has its own connector, but I don‘t know whether it works or does not work with Python 3.4. Connecting to MySQL Using Connector/Python I will have to look into this more.

Any advice on how to connect Python 3.4 with MySQL?

python mysql


shareimprove this question

edited Jun 1 ‘15 at 0:43

asked Jun 1 ‘15 at 0:36

Steve R.

71214

 
add a comment

1 Answer

activeoldestvotes


up vote0down voteaccepted

The documentation for MySQL Connector/Python says Version 2.0 should work with MySQL Server 5.5-5.7 and Python 3.3 and later. So I would say it‘s a good bet. If it doesn‘t work, follow up with what error you encounter and I‘ll see if I can help.


shareimprove this answer

answered Jun 1 ‘15 at 5:10

Synergist

24718

 

    

Thanks. Will give it a try. – Steve R. Jun 1 ‘15 at 17:27
    

Let me know if it works please. – Synergist Jun 1 ‘15 at 17:43
    

Sort of. When I type in just plain python then " import mysql.connector" it works. When I type in python3then " import mysql.connector" it fails with the message "ImportError: No module named ‘mysql‘". Implies a configuration issue (such as path) with Python 3.4.0? – Steve R. Jun 1 ‘15 at 18:04
    

How did you install MySQL Connector? – Synergist Jun 1 ‘15 at 18:09
    

Turns out that the new version is available through the Ubuntu Software Center. However, I had to remove the old "python-mysql.connector" (version 1.1.6-1) before I could install the new version of the python connector. I only ran the install from the Ubuntu Software Center. Did not underake any other configuration. – Steve R.Jun 1 ‘15 at 18:20

时间: 2024-10-07 07:23:53

How to Access MySQL with Python Version 3.4的相关文章

安装第三方库出现 Python version 2.7 required, which was not found in the registry

安装第三方库出现 Python version 2.7 required, which was not found in the registry 建立一个文件 register.py 内容如下. 然后执行该脚本. import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythonco

Python version 3.3 required, which was not found in the registry

python registry函数语法 在windows下安装numpy的时候, 出现了"Python version 3.3 required, which was not found in the registry"的错误. 类似的有:Python version 2.7 required, which was not found in the registry 大致意思是说:注册表没有对应的信息. 只要执行一个python脚本,将HKEY_CURRENT_USER (HKCU)注

在Ubuntu上安装Mysql For Python

安装: 首先安装pip,并且把pip更新到最小版本 apt-get install python-pip pip install -U pip 安装mysql开发包 apt-get install python-dev libmysqlclient-dev 通过pip安装Mysql For Python pip install MySQL-python 测试,在Python命令行里输入import MySQLdb,看报不报错 [email protected]:~$ python Python

python version 2.7 required,which was not found in the registry

安装Mysql-python的时候,不能再注册表中识别出来python2.7 方法:新建一个register.py 文件,把以下代码贴进去,保存 ## script to register Python 2.0 or later for use with win32all# and other extensions that require Python registry settings## written by Joakim Loew for Secret Labs AB / PythonW

Installing MySQL Connector/Python using pip v1.5

The latest pip versions will fail on you when the packages it needs to install are not hosted on PyPI . When you try to install MySQL Connector/Python the usually way, you get following message is: shell> pip install mysql-connector-python Could not

【转】Python version 2.7 required, which was not found in the registry

安装setuptools的时候,不能再注册表中识别出来python2.7 在网上找了方法,仅作笔记,供下次使用 方法: 新建一个register.py 文件,把一下代码贴进去,保存(G盘) 1 # 2 # script to register Python 2.0 or later for use with win32all 3 # and other extensions that require Python registry settings 4 # 5 # written by Joak

MySQL Connector/Python 开发者指南

本文翻译自:https://dev.mysql.com/doc/connector-python/en/ 摘要 这篇手册描述了怎么来安装和配置 MySQL Connector/Python,MySQL Connector/Python 是 Python 和 MySQL 服务进行通信的一个独立驱动程序,本篇手册还将阐述如何利用它来开发数据库应用程序. 获取 Connector/Python 的每一次发布版本的改动细节,请参阅 MySQL Connector/Python Release Notes

未能加载文件或程序集“MySql.Web.v20, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或它的某一个依赖项。系统找不到指定的文件

未能加载文件或程序集“MySql.Web.v20, Version=6.9.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d”或它的某一个依赖项.系统找不到指定的文件 用mysql时提示这个错误,百度半天,后来好不容易搜到这个解决方法 修改 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config 与 C:\Windows\Microsoft.NET\Frame

【亲测】Python:解决方案:Python Version 2.7 required, which was not found in the registry

好久不更新随笔了,今天因为数据可视化作业,想抓取一些人人网好友关系数据,于是开始尝试python,用到numpy模块,安装的时候提示: 'Python Version 2.7 required, which was not found in the registry' 发现很多人都遇到这个问题,网上说是官方不支持包,然后给了另外的链接让去下非官方版的,结果没找到囧... 于是发现了这个帖子,直接解决了问题,果断贴过来,帮助其他和我一样遭遇的人儿们. 原帖地址:http://www.xue5.co