一、问题现象
报错信息如下:
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 mainreturn command.main(cmd_args)^^^^^^^^^^^^^^^^^^^^^^File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 101, in mainreturn self._main(args)^^^^^^^^^^^^^^^^File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/base_command.py", line 236, in _mainself.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_checksession = self._build_session(^^^^^^^^^^^^^^^^^^^^File "/user_name/anaconda3/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 125, in _build_sessionsession = 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_hostraise 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/simple3 [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/simple3 [install]4 trusted-host = https://pypi.tuna.tsinghua.edu.cn