Mac环境下为Python安装MySQLdb库时遇到的诸多问题

来源:互联网 发布:voip软件电话 编辑:程序博客网 时间:2024/05/22 06:53

安装MySQLdb时需要了诸多很多问题:
1、使用$ pip3 install mysql-connector-python
Collecting mysql-connector-python
命令,
报错

Collecting mysql-connector-python  Could not find a version that satisfies the requirement mysql-connector-python (from versions: )No matching distribution found for mysql-connector-python

待解决

2、网上有人给出命令:$ pip3 install mysql-connector-python-rf
报错:

    error: option --single-version-externally-managed not recognized    ----------------------------------------Command "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/xx/l7vbvpvj4lz6_r9cg083hr1m0000gn/T/pip-build-mm187beq/mysql-connector-python-rf/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/xx/l7vbvpvj4lz6_r9cg083hr1m0000gn/T/pip-flk4dyws-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/xx/l7vbvpvj4lz6_r9cg083hr1m0000gn/T/pip-build-mm187beq/mysql-connector-python-rf/

待解决

3。最后是使用下载压缩文件,使用命令安装的,但需要修改,压缩文件“setup_posix.py“中的mysql_config.path = "/mysql_config"
这一句要修改为自己本地mysql的路径。比如我的是

mysql_config.path = "/Users/xu/Documents/JavaTools/mysql/bin/mysql_config"

下载文件地址:http://sourceforge.net/projects/mysql-python/files/

使用命令:
1、cd 目录地址
2、$ python3 setup.py install
3、使用python导入测试: import MySQLdb

资料参考:https://segmentfault.com/a/1190000000329202

二、安装 mysql-connector-python-rf
原命令:

pip install mysql-connector-python –allow-external mysql-connector-python

命令遇到错误

Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python

解决办法:

1、从官方下载最新的源码包

下载地址:https://pypi.python.org/pypi/mysql-connector-python-rf/2.1.3

2、从cmd进入解压好的安装包目录中

3、使用python setup.py build

4、使用python setup.py install

0 0
原创粉丝点击