一、更新pip和setuptools工具
>>> sudo pip install pip -U
>>> sudo pip install setuptools -U
如果上一步執行后,還是安裝不了,就執行第二步
二、仔細查看錯誤信息,尋找缺失的依賴項,安裝了缺失的依賴項后,再進行安裝
例如:
pip install --user mmcv --trusted-host yum.tbsite.net Looking in indexes: http://yum.tbsite.net/pypi/simple/ Collecting mmcv Downloading http://yum.tbsite.net/pypi/packages/26/fa/f032c1e0095b4dfac42feae2f4e8ad77dd3ad83257cb5269814c583ac34c/mmcv-0.2.14.tar.gz (48kB) |████████████████████████████████| 51kB 19.6MB/s ERROR: Command errored out with exit status 1: command: /opt/conda/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-td71coct/mmcv/setup.py'"'"'; __file__='"'"'/tmp/pip-install-td71coct/mmcv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-td71coct/mmcv/pip-egg-info cwd: /tmp/pip-install-td71coct/mmcv/ Complete output (33 lines): WARNING: The repository located at yum.tbsite.net is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host yum.tbsite.net'. ERROR: Could not find a version that satisfies the requirement pytest-runner (from versions: none) ERROR: No matching distribution found for pytest-runner Traceback (most recent call last): File "/home/admin/.local/lib/python3.6/site-packages/setuptools/installer.py", line 119, in fetch_build_egg subprocess.check_call(cmd) File "/opt/conda/lib/python3.6/subprocess.py", line 291, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/opt/conda/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp8ffnblrb', '--quiet', '--index-url', 'http://yum.tbsite.net/pypi/simple', 'pytest-runner']' returned non-zero exit status 1. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-td71coct/mmcv/setup.py", line 83, in <module> zip_safe=False) File "/home/admin/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 144, in setup _install_setup_requires(attrs) File "/home/admin/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires dist.fetch_build_eggs(dist.setup_requires) File "/home/admin/.local/lib/python3.6/site-packages/setuptools/dist.py", line 721, in fetch_build_eggs replace_conflicting=True, File "/home/admin/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 782, in resolve replace_conflicting=replace_conflicting File "/home/admin/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1065, inbest_match return self.obtain(req, installer) File "/home/admin/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1077, inobtain return installer(requirement) File "/home/admin/.local/lib/python3.6/site-packages/setuptools/dist.py", line 777, in fetch_build_egg return fetch_build_egg(self, req) File "/home/admin/.local/lib/python3.6/site-packages/setuptools/installer.py", line 121, in fetch_build_egg raise DistutilsError(str(e)) distutils.errors.DistutilsError: Command '['/opt/conda/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmp8ffnblrb', '--quiet', '--index-url', 'http://yum.tbsite.net/pypi/simple', 'pytest-runner']' returned non-zero exit status 1. ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output
對於上面這個錯誤,通過閱讀錯誤提示發現,少了一個依賴項pytest-runner
WARNING: The repository located at yum.tbsite.net is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host yum.tbsite.net'. ERROR: Could not find a version that satisfies the requirement pytest-runner (from versions: none)
安裝了這個依賴項后,再安裝mmcv這個第三方包就沒問題了。
三、補充
導致pip安裝第三方包出現錯誤的原因有很多,比如網絡中斷、使用國外的python源(下載超時)等等。
