赞
踩
当你采用pip安装第三方库时出现No module named ‘_distutils_hack‘错误,多半原因是由于setuptools库版本不对导致,下文将介绍具体处理方法。
我在安装ultralytics时,当执行如下命令时报错:
pip install -e .
错误如下:
(yolo) D:\JupyterNotebookProject\ultralytics>pip install -e .
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Obtaining file:///D:/JupyterNotebookProject/ultralytics
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [9 lines of output]
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))': /pypi/web/simple/setuptools/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))': /pypi/web/simple/setuptools/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))': /pypi/web/simple/setuptools/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))': /pypi/web/simple/setuptools/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))': /pypi/web/simple/setuptools/
Could not fetch URL https://mirrors.ustc.edu.cn/pypi/web/simple/setuptools/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='mirrors.ustc.edu.cn', port=443): Max retries exceeded with url: /pypi/web/simple/setuptools/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1122)'))) - skipping
ERROR: Could not find a version that satisfies the requirement setuptools>=43.0.0 (from versions: none)
ERROR: No matching distribution found for setuptools>=43.0.0
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
可以看到错误原因是我的setuptools版本不对,于是查询setuptools版本,如下所示:
(yolo) D:\JupyterNotebookProject\ultralytics>pip list
Package Version
----------------- -----------
filelock 3.13.1
fsspec 2023.12.2
Jinja2 3.1.3
MarkupSafe 2.1.3
mpmath 1.3.0
networkx 3.2.1
pip 23.3.1
setuptools 68.2.2
sympy 1.12
torch 2.1.2+cu118
typing_extensions 4.9.0
wheel 0.41.2
我的setuptools版本为68.2.2,而上文错误中要求setuptools版本必须大于43.0.0,于是决定将setuptools卸载后再安装低版本,具体操作如下:
(yolo) D:\JupyterNotebookProject\ultralytics>pip3 install setuptools==45.0.0
Error processing line 1 of D:\Users\laowu\Anaconda3\envs\yolo\lib\site-packages\distutils-precedence.pth:
Traceback (most recent call last):
File "D:\Users\laowu\Anaconda3\envs\yolo\lib\site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
Remainder of file ignored
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting setuptools==45.0.0
Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/af/e7/02db816dc88c598281bacebbb7ccf2c9f1a6164942e88f1a0fded8643659/setuptools-45.0.0-py2.py3-none-any.whl (583 kB)
---------------------------------------- 583.8/583.8 kB 733.4 kB/s eta 0:00:00
Installing collected packages: setuptools
Successfully installed setuptools-45.0.0
从上面的代码中可以看出,setuptools成功安装了,但是报错了,错误就是:
ModuleNotFoundError: No module named '_distutils_hack'
但是我并未管,继续重新安装ultralytics,此时安装成功,但是安装过程显示依然有错,如下:
(yolo) D:\JupyterNotebookProject\ultralytics>pip install -e .
Error processing line 1 of D:\Users\laowu\Anaconda3\envs\yolo\lib\site-packages\distutils-precedence.pth:
Traceback (most recent call last):
File "D:\Users\laowu\Anaconda3\envs\yolo\lib\site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
既然安装成功,我便未理会错误,但是在执行命令时发现错误依旧存在,如下:
(yolo) D:\JupyterNotebookProject\ultralytics>yolo
Error processing line 1 of D:\Users\laowu\Anaconda3\envs\yolo\lib\site-packages\distutils-precedence.pth:
Traceback (most recent call last):
File "D:\Users\laowu\Anaconda3\envs\yolo\lib\site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
我意识到必须处理了,于是通过查询,发现导致问题的根本原因是由于setuptools版本不对导致。
查到此问题,我是在issueantenna网上,具体链接如下:
ModuleNotFoundError: No module named ‘_distutils_hack’
由于部分国内网友可能无法访问该网页,我将其截图如下:
根据文中方法,我将setuptools版本降级为57.5.0后问题成功解决。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。