问题
How do I fix my apparently-corrupted Python 2.7.16 install? (fwiw, my Python3 seems to run fine.)
It is a homebrew-based, macOS 10.14.6 install.
I get a Traceback generated for most every pip command, including 'pip --version' as noted below, with this error: ImportError: cannot import name ThreadingTCPServer
. Details below. I've not yet tried to debug the install; ie, the ThreadingTCPServer
is defined in one of the Cellar files, but I do not yet understand why it's import fails. Maybe it's not a proper module?
I of course have web searched and found no symptoms with exactly the same error.
$ pip --version
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/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 46, in <module>
from SocketServer import ThreadingTCPServer, StreamRequestHandler
ImportError: cannot import name ThreadingTCPServer
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G95
$ which pip2.7
/usr/local/bin/pip2.7
$ python2 --version
Python 2.7.16
$
The homebrew info:
$ brew info python2
python@2: stable 2.7.16 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python@2/2.7.16 (6,543 files, 90.3MB) *
Built from source on 2019-04-17 at 15:50:57
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python@2.rb
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl@1.1 ✔, readline ✔, sqlite ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 105,877 (30 days), 313,398 (90 days), 1,630,127 (365 days)
install_on_request: 38,093 (30 days), 100,736 (90 days), 436,798 (365 days)
build_error: 0 (30 days)
$
More session and system details at this gist.
来源:https://stackoverflow.com/questions/58347930/traceback-generated-for-every-pip-command-importerror-cannot-import-name-thre