Mac 安装 python 之后 pip 出错:ERROR:root:code for hash md5 was not found.
我在想安装 mysql-connnector
时,使用 pip install mysql-connector
报错了,找了半天没找到答案。
错误如下:
Kyle@Kyles-MBP bin % pip
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==19.0.3', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2793, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2411, in load
return self.resolve()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2417, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/site-packages/pip/_internal/__init__.py", line 19, in <module>
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 29, in <module>
from .connection import (
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/connection.py", line 38, in <module>
from .util.ssl_ import (
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/util/__init__.py", line 6, in <module>
from .ssl_ import (
File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/util/ssl_.py", line 8, in <module>
from hashlib import md5, sha1, sha256
ImportError: cannot import name md5
原因
不管你是通过官网下载的 .pkg
安装的,还是通过 brew
的,可能都会遇到这个问题。
原因是:Mac 系统自带有 python 2.7
而你输入 pip
时调用的就是自带的 python
并不是你安装的 python
。
Mac 系统中随机带的 python
使用 python
和 pip
来使用,而你后来安装的就需要使用 python3
和 pip3
使用。
为什么?
看 python
指令调用的内容就知道:
Kyle@Kyles-MBP lib % cd /usr/local/bin/
Kyle@Kyles-MBP bin % ll | grep python
lrwxr-xr-x 1 Kyle admin 36 Apr 10 2019 2to3-2 -> ../Cellar/python@2/2.7.16/bin/2to3-2
lrwxr-xr-x 1 Kyle admin 38 Apr 10 2019 2to3-2.7 -> ../Cellar/python@2/2.7.16/bin/2to3-2.7
lrwxr-xr-x 1 Kyle admin 42 Apr 10 2019 easy_install -> ../Cellar/python@2/2.7.16/bin/easy_install
lrwxr-xr-x 1 Kyle admin 46 Apr 10 2019 easy_install-2.7 -> ../Cellar/python@2/2.7.16/bin/easy_install-2.7
lrwxr-xr-x 1 Kyle admin 34 Apr 10 2019 idle -> ../Cellar/python@2/2.7.16/bin/idle
lrwxr-xr-x 1 Kyle admin 35 Apr 10 2019 idle2 -> ../Cellar/python@2/2.7.16/bin/idle2
lrwxr-xr-x 1 Kyle admin 37 Apr 10 2019 idle2.7 -> ../Cellar/python@2/2.7.16/bin/idle2.7
lrwxr-xr-x 1 Kyle admin 33 Apr 10 2019 pip -> ../Cellar/python@2/2.7.16/bin/pip
lrwxr-xr-x 1 Kyle admin 34 Apr 10 2019 pip2 -> ../Cellar/python@2/2.7.16/bin/pip2
lrwxr-xr-x 1 Kyle admin 36 Apr 10 2019 pip2.7 -> ../Cellar/python@2/2.7.16/bin/pip2.7
lrwxr-xr-x 1 Kyle admin 35 Apr 10 2019 pydoc -> ../Cellar/python@2/2.7.16/bin/pydoc
lrwxr-xr-x 1 Kyle admin 36 Apr 10 2019 pydoc2 -> ../Cellar/python@2/2.7.16/bin/pydoc2
lrwxr-xr-x 1 Kyle admin 38 Apr 10 2019 pydoc2.7 -> ../Cellar/python@2/2.7.16/bin/pydoc2.7
lrwxr-xr-x 1 Kyle admin 36 Apr 10 2019 python -> ../Cellar/python@2/2.7.16/bin/python
lrwxr-xr-x 1 Kyle admin 43 Apr 10 2019 python-config -> ../Cellar/python@2/2.7.16/bin/python-config
lrwxr-xr-x 1 Kyle admin 37 Apr 10 2019 python2 -> ../Cellar/python@2/2.7.16/bin/python2
lrwxr-xr-x 1 Kyle admin 44 Apr 10 2019 python2-config -> ../Cellar/python@2/2.7.16/bin/python2-config
lrwxr-xr-x 1 Kyle admin 39 Apr 10 2019 python2.7 -> ../Cellar/python@2/2.7.16/bin/python2.7
lrwxr-xr-x 1 Kyle admin 46 Apr 10 2019 python2.7-config -> ../Cellar/python@2/2.7.16/bin/python2.7-config
lrwxr-xr-x 1 root wheel 69 Oct 29 12:03 python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3
lrwxr-xr-x 1 root wheel 76 Oct 29 12:03 python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3-config
lrwxr-xr-x 1 root wheel 71 Oct 29 12:03 python3.9 -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
lrwxr-xr-x 1 root wheel 78 Oct 29 12:03 python3.9-config -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9-config
lrwxr-xr-x 1 Kyle admin 37 Apr 10 2019 pythonw -> ../Cellar/python@2/2.7.16/bin/pythonw
lrwxr-xr-x 1 Kyle admin 38 Apr 10 2019 pythonw2 -> ../Cellar/python@2/2.7.16/bin/pythonw2
lrwxr-xr-x 1 Kyle admin 40 Apr 10 2019 pythonw2.7 -> ../Cellar/python@2/2.7.16/bin/pythonw2.7
lrwxr-xr-x 1 Kyle admin 38 Apr 10 2019 smtpd.py -> ../Cellar/python@2/2.7.16/bin/smtpd.py
lrwxr-xr-x 1 Kyle admin 41 Apr 10 2019 smtpd2.7.py -> ../Cellar/python@2/2.7.16/bin/smtpd2.7.py
lrwxr-xr-x 1 Kyle admin 39 Apr 10 2019 smtpd2.py -> ../Cellar/python@2/2.7.16/bin/smtpd2.py
lrwxr-xr-x 1 Kyle admin 35 Apr 10 2019 wheel -> ../Cellar/python@2/2.7.16/bin/wheel
对应的还有 pip
,pip
是管理 python
包的工具
Kyle@Kyles-MBP lib % cd /usr/local/bin/
Kyle@Kyles-MBP bin % ll | grep pip
lrwxr-xr-x 1 Kyle admin 33 Apr 10 2019 pip -> ../Cellar/python@2/2.7.16/bin/pip
lrwxr-xr-x 1 Kyle admin 34 Apr 10 2019 pip2 -> ../Cellar/python@2/2.7.16/bin/pip2
lrwxr-xr-x 1 Kyle admin 36 Apr 10 2019 pip2.7 -> ../Cellar/python@2/2.7.16/bin/pip2.7
lrwxrwxr-x 1 root admin 66 Oct 29 12:03 pip3 -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
lrwxrwxr-x 1 root admin 68 Oct 29 12:03 pip3.9 -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
安装成功
然后通过下面指令就能成功安装了
pip3 install mysql-connector
Kyle@Kyles-MBP ~ %
Collecting mysql-connector
Downloading mysql-connector-2.2.9.tar.gz (11.9 MB)
|████████████████████████████████| 11.9 MB 99 kB/s
Using legacy 'setup.py install' for mysql-connector, since package 'wheel' is not installed.
Installing collected packages: mysql-connector
Running setup.py install for mysql-connector ... done
Successfully installed mysql-connector-2.2.9