本文由 简悦 SimpRead 转码, 原文地址 blog.csdn.net
似乎是更新过一次pip,再安装就这样报错了,删掉注释后已经恢复正常。
一、问题现象
报错信息如下:
Traceback (most recent call last):
File "/user_name/anaconda3/bin/pip", line 11, in <module>
sys.exit(main())
^^^^^^
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/main.py", line 79, in main
return command.main(cmd_args)
^^^^^^^^^^^^^^^^^^^^^^
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 101, in main
return self._main(args)
^^^^^^^^^^^^^^^^
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 236, in _main
self.handle_pip_version_check(options)
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 180, in handle_pip_version_check
session = self._build_session(
^^^^^^^^^^^^^^^^^^^^
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_session
session = PipSession(
^^^^^^^^^^^
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/network/session.py", line 398, in __init__
self.add_trusted_host(host, suppress_logging=True)
File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/network/session.py", line 424, in add_trusted_host
raise ValueError(f"Trusted host URL must include a host part: {host!r}")
ValueError: Trusted host URL must include a host part: '#'
二、问题原因
vi ~/.pip/pip.conf
1 [global]
2 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3 [install]
4 trusted-host = https://pypi.tuna.tsinghua.edu.cn # trusted-host 此参数是为了避免麻烦,否则使用的
主要原因是第 4 行后面的注释内容导致的
三、解决问题
把 ~/.pip/pip.conf 改成下面这样即可
1 [global]
2 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3 [install]
4 trusted-host = https://pypi.tuna.tsinghua.edu.cn
Comments | NOTHING