所以我尝试了多种方法来安装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。
答案 0 :(得分:1)
我可以通过运行@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?
答案 1 :(得分:-1)
也许使用brew?
brew cask install mysql-connector-python