mysql-python 不会在 MacOS 上安装
Posted
技术标签:
【中文标题】mysql-python 不会在 MacOS 上安装【英文标题】:mysql-python won't install on MacOS 【发布时间】:2018-08-04 01:16:33 【问题描述】:所以我尝试了多种方法来安装mysql-python和MYSQLdb。我尝试通过此链接下载:https://sourceforge.net/projects/mysql-python/,然后当我运行python setup.py install
时出现以下错误:
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Traceback (most recent call last):
File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 143, in use_setuptools
raise ImportError
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "setup.py", line 7, in <module>
use_setuptools()
File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 124, in _do_download
to_dir, download_delay)
File "/Users/Jackson/Google Drive/CS520/HW/MySQL-python-1.2.4b4/distribute_setup.py", line 194, in download_setuptools
src = urlopen(url)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Users/Jackson/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: SSL is required
我找不到有效的解决方案,所以我尝试了pip install mysql-python
,然后我得到以下结果
Traceback (most recent call last):
File "setup.py", line 6, in <module>
req = urllib.request.Request(url, headers='User-Agent': 'Mozilla/5.0')
NameError: name 'url' is not defined
Jacksons-MacBook-Pro:MySQL-python-1.2.4b4 Jackson$ pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-build-kdgbz3qe/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/tmp/pip-build-kdgbz3qe/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-kdgbz3qe/mysql-python/
当我查看这个问题时,我尝试运行:
pip install --upgrade setuptools
pip install ez_setup
easy_install -U setuptools
没有问题,但是当我尝试重新运行命令pip install mysql-python
时,我得到了和以前一样的错误。我尝试下载 mysqlclient 和 mysql/python 连接器,但没有任何效果。我只想修复尝试安装 mysql-python、mysqlclient、MYSQLdb、mysql/python 连接器或任何可以实际工作的东西。我已经安装并运行了 mysql 以及 Sequel Pro。
【问题讨论】:
【参考方案1】:也许使用 brew?
brew cask install mysql-connector-python
见https://apple.stackexchange.com/questions/130324/how-to-install-mysql-utilities-using-brew-or-brew-cask#136180
【讨论】:
谢谢。这有效,但必须添加pip search mysql-connector | grep --color mysql-connector-python
然后 pip install mysql-connector-python-rf
【参考方案2】:
我可以通过运行@Devstr 和@jsteele 的组合来解决这个问题。我意识到从python连接到mysql的python模块不是mysql
而是```mysql-connector``。
按照以下步骤操作:
brew cask install mysql-connector-python
pip search mysql-connector | grep --color mysql-connector-python
pip install mysql-connector-python-rf
然后在python中:
import mysql.connector
...
找到一些有用的信息:What's the difference between MySQLdb, mysqlclient and MySQL connector/Python?
【讨论】:
以上是关于mysql-python 不会在 MacOS 上安装的主要内容,如果未能解决你的问题,请参考以下文章
MySQL-python 安装 - 错误的架构 - MacOS
MacOS Mojave 10.14.4 安装 MySQLdb 报错处理