pip install pytrec_eval失败的解决方案
1、问题描述
在使用华为云 notebook 的时候,想要:
!pip install transformer
结果失败,阅读报错后,疑似是 pytrec_eval
库的下载问题。
于是,单独尝试:
!pip install pytrec_eval
发现确实是这个库安装失败,具体报错内容如下:
Processing ./pytrec_eval-0.5.tar.gz
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [44 lines of output]
Traceback (most recent call last):
File "/usr/lib/python3.10/urllib/request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/lib/python3.10/http/client.py", line 1283, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1329, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 976, in send
self.connect()
File "/usr/lib/python3.10/http/client.py", line 1455, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/usr/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake()
File "/usr/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-req-build-o24w6fkg/setup.py", line 27, in <module>
response = urllib.request.urlopen(REMOTE_TREC_EVAL_URI)
File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/usr/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/lib/python3.10/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/lib/python3.10/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)>
Fetching trec_eval from https://github.com/usnistgov/trec_eval/archive/v9.0.8.tar.gz.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
2、尝试解决
根据报错中的
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)
和
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1007)>
Fetching trec_eval from https://github.com/usnistgov/trec_eval/archive/v9.0.8.tar.gz.
我猜测是因为下载时需要连接某个站点,但因网络问题 or 外网访问的限制等等,总之最终结果就是连接不上。
在网络上搜索一番,基本全是水得要死的文章内容,跟这个问题的解决不能说是毫无关联,那也是空泛无用。
好在,仍然有人讨论过类似的问题(原链接点此处),考虑到目前难以找到确切的解决方案,我决定自己整理一下这个问题的解决方法。
3、我的解决方法
首先把 pytrec_eval
库下载到本地,下载链接点击此处。
解压这个文件夹(Windows和Linux各有自己的解压方法,如果你不知道怎么解压文件,可以自行搜索)
这里是以 windows 系统为例,在 cmd
命令行里进入解压后的文件夹,然后尝试如下代码:
python setup.py install
如果用的是 .ipynb
,相应的代码则是:
%run setup.py install
此时大概率还是报错,因为它连接不到一个叫作 trec_eval
的库。
为了解决这个问题,类似地,我们需要把 trec_eval
库下载到本地,下载链接点击此处。
下载好以后,直接把这个压缩包 trec_eval-9.0.8.tar.gz
整个丢进 pytrec_eval
的解压文件夹里面。
打开 pytrec_eval
解压文件夹里面的 setup.py
文件,修改第 8 行的 REMOTE_TREC_EVAL_URI
参数,修改的内容为:
REMOTE_TREC_EVAL_URI = 'file:你的trec_eval-9.0.8.tar.gz的地址'
例如,如果你已经按我说的,把压缩包 trec_eval-9.0.8.tar.gz
整个丢进了 pytrec_eval
的解压文件夹里面,相应的代码是:
REMOTE_TREC_EVAL_URI = 'file:trec_eval-9.0.8.tar.gz'
修改好以后保存 setup.py
文件。
现在,再次尝试
python setup.py install
或
%run setup.py install
成功。
看在写得这么细致的份上,如果有帮助到你的话,能否给我留下一个赞呢?谢谢你啦~
有其他问题也可以在评论区讨论。