我在 Win10 中使用 anaconda Powershell Prompt。使用 pip(版本:21.2.4)安装包时报告 UnicodeDecodeError。我发现内核 Python 3.6.7 和 Python 3.9.7 都会报这个错误。安装和升级都失败,报同样的错误。我试过以下命令。
pip install simplejson
pip install simplejson --upgrade
包可以是任何东西并报告相同的错误。
使用 Windows CMD 报告了相同的错误。我使用 Windows CMD 尝试了以下命令。
py -m pip install simplejson
py -m pip install --upgrade pip
这是我得到的错误报告。
ERROR: Exception:
Traceback (most recent call last):
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\cli\base_command.py", line 173, in _main
status = self.run(options, args)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\cli\req_command.py", line 203, in wrapper
return func(self, options, args)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
requirement_set = resolver.resolve(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 472, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
return bool(self._sequence)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 140, in __bool__
return any(self)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 128, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 29, in _iter_built
for version, func in infos:
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 272, in iter_index_candidate_infos
result = self._finder.find_best_candidate(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 851, in find_best_candidate
candidates = self.find_all_candidates(project_name)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 798, in find_all_candidates
page_candidates = list(page_candidates_it)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
yield from self._candidates_from_page(self._link)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\package_finder.py", line 758, in process_project_url
html_page = self._link_collector.fetch_page(project_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 490, in fetch_page
return _get_html_page(location, session=self.session)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 400, in _get_html_page
resp = _get_html_response(url, session=session)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\index\collector.py", line 115, in _get_html_response
resp = session.get(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\session.py", line 454, in request
return super().request(method, url, *args, **kwargs)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 528, in request
prep = self.prepare_request(req)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions.py", line 456, in prepare_request
p.prepare(
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\models.py", line 320, in prepare
self.prepare_auth(auth, url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\models.py", line 556, in prepare_auth
r = auth(self)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 208, in __call__
url, username, password = self._get_url_and_credentials(req.url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 180, in _get_url_and_credentials
username, password = self._get_new_credentials(original_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_internal\network\auth.py", line 145, in _get_new_credentials
netrc_auth = get_netrc_auth(original_url)
File "E:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\requests\utils.py", line 216, in get_netrc_auth
_netrc = netrc(netrc_path).authenticators(host)
File "E:\Program Files\Anaconda3\lib\netrc.py", line 30, in __init__
self._parse(file, fp, default_netrc)
File "E:\Program Files\Anaconda3\lib\netrc.py", line 39, in _parse
toplevel = tt = lexer.get_token()
File "E:\Program Files\Anaconda3\lib\shlex.py", line 109, in get_token
raw = self.read_token()
File "E:\Program Files\Anaconda3\lib\shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence
我已经重新安装了 pip、Anaconda 和 python 解释器。它仍然失败。我认为这与点子无关。输入流出现问题。默认解码格式为“GBK”。我尝试使用以下命令将解码格式更改为“utf-8”。它再次失败并出现同样的错误。
chcp 65001
感谢@Mobfi 的建议,我尝试了其他类似的命令,它们返回相同的错误通知。
chcp 437
chcp 850
感谢@BoarGules 的建议,我用utf-8 解码器启动python 并尝试用pip 安装/升级包。
py -X utf8
我在 powershell 中启动了 python 控制台。导入 pip pip.main(['install', 'simplejson'])
除了类似的回溯,我得到了另一个新的回溯:
*same as aforementioned traceback*
File "E:\Program Files\Anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
有人可以帮忙吗?欢迎任何潜在的解决方案、线索或类似经验。