简体   繁体   English

无法在MacOS Mojave的Python 2.7上安装MySQLdb

[英]Unable to install MySQLdb on Python 2.7 on MacOS Mojave

I used to create a big program in Python 2.7 that uses MySQLdb a long time ago. 我很久以前曾经在Python 2.7中创建一个使用MySQLdb的大型程序。 I developed it both on Mac OS and PC. 我在Mac OS和PC上都进行了开发。 I just had to re-refomat my Mac and I'm now on Mojave. 我只需要重新修改Mac,就可以使用Mojave。 Whereas I have been able in the past to easily install MySQLdb, I'm unable to do so now. 过去我能够轻松安装MySQLdb,但现在无法这样做。

I've tried all that was available on the forums with no success. 我尝试了所有在论坛上可用的方法,但都没有成功。 PIP, easy-install, Brew and many other solutions that I forgot. PIP,易于安装,Brew和许多其他我忘记的解决方案。 Even "easy_install MySQL-python" found in Installing MySQLDB on Python 2.7.3 under CentOS gave me an error ending by : EnvironmentError: mysql_config not found 甚至在CentOS下在Python 2.7.3上安装MySQLDB中发现的“ easy_install MySQL-python”也给我一个以结尾的错误:EnvironmentError:mysql_config not found

I expect to be able to "import MySQLdb" in my Python code, but MySQLdb isn't installed and so "no found" 我希望能够在我的Python代码中“导入MySQLdb”,但未安装MySQLdb,因此“未找到”

Thanks a lot for your help. 非常感谢你的帮助。

So, you either have upgrade your MySQL Version to a 64Bit Version, get the newest MySQL-Python Connector, update your code and use this instead of MySQLdb. 因此,您可以将MySQL版本升级到64位版本,获取最新的MySQL-Python连接器,更新代码,然后使用它代替MySQLdb。 Which is the safest and best solution, but u have to put in some work (no problem if your code isn't that long anyways...) 这是最安全和最佳的解决方案,但是您必须进行一些工作(如果您的代码这么长,没问题……)

https://dev.mysql.com/downloads/connector/python/ https://dev.mysql.com/downloads/connector/python/

https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html https://dev.mysql.com/doc/connector-python/zh-CN/connector-python-example-connecting.html

import mysql.connector

Second chance is, staying with your old 32Bit MySQL Version (for Example 5.6.20 32Bit), and still using the same old MySQL Python Connector (For Example Mysql-Python Connector 1.2.3 in 32Bit, found on the Mysql Download page aswell) you used before. 第二次机会是,继续使用旧的32Bit MySQL版本(例如5.6.20 32Bit),并仍使用相同的旧MySQL Python连接器(例如32Bit的Mysql-Python Connector 1.2.3,也可在Mysql下载页面上找到)你以前用过 There will be some popup errors, such as a few Libraries are out of date and probably not compatible anymore, but it's working. 将会出现一些弹出错误,例如一些库已过时并且可能不再兼容,但是它正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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