Python 2.7:LookupError:未知编码:cp65001 [英] Python 2.7 : LookupError: unknown encoding: cp65001
问题描述
我已经在Windows 8.1(64位)上安装了python 2(64位),并且想知道pip版本,因此我触发了pip --version
,但它给出了错误.
I have installed python 2(64 bit), on windows 8.1 (64 bit) and wanted to know pip version and for that I fired pip --version
but it is giving error.
C:\Users\ADMIN>pip --version
Traceback (most recent call last):
File "c:\dev\python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\dev\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\dev\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "c:\dev\python27\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "c:\dev\python27\lib\site-packages\pip\vcs\mercurial.py", line 10, in <module>
from pip.download import path_to_url
File "c:\dev\python27\lib\site-packages\pip\download.py", line 35, in <module>
from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
File "c:\dev\python27\lib\site-packages\pip\utils\ui.py", line 51, in <module>
_BaseBar = _select_progress_class(IncrementalBar, Bar)
File "c:\dev\python27\lib\site-packages\pip\utils\ui.py", line 44, in _select_progress_class
six.text_type().join(characters).encode(encoding)
LookupError: unknown encoding: cp65001
注意:相同的命令适用于python3.我已经卸载了这两个软件并重新安装,但仍然没有成功.
Note : The same command works fine for python 3. I have uninstalled both and installed again but still no success.
推荐答案
该错误表示您的脚本尝试打印的Unicode字符无法使用当前的控制台字符编码来表示.
The error means that Unicode characters that your script are trying to print can't be represented using the current console character encoding.
还可以尝试在执行pip --version 而无需重新加载终端后运行set PYTHONIOENCODING=UTF-8
,如果一切顺利,请将PYTHONIOENCODING
添加为具有值UTF-8
的env变量.请参阅如何在Windows中设置路径和环境变量文章以获取有关如何添加的信息Windows变量.
Also try to run set PYTHONIOENCODING=UTF-8
after execute pip --version without reloading terminal if everything going well add PYTHONIOENCODING
as env variable with value UTF-8
. See How to set the path and environment variables in Windows article to get info how to add Windows variable.
注意:对于PowerShell,请使用$env:PYTHONIOENCODING = "UTF-8"
NOTE: For PowerShell use $env:PYTHONIOENCODING = "UTF-8"
另外,您可以尝试使用pip安装 win-unicode-console :
Also you can try to install win-unicode-console with pip:
pip install win-unicode-console
然后重新加载终端并尝试执行pip --version
Then reload your terminal and try to execute pip --version
但是,您可以遵循 Windows中的建议cmd编码更改会导致Python崩溃答案,因为您遇到相同的问题.
However you can follow suggestions from Windows cmd encoding change causes Python crash answer because you have same problem.
这篇关于Python 2.7:LookupError:未知编码:cp65001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!