4

我使用 Python 2.7 和 pip 全新安装了 Windows 7 x64 Professional。安装过程中没有错误,但是当我尝试pip install xlrd在 CMD 中时,我得到了下一个:

C:\Users\Владислав>pip install xlrd

Downloading/unpacking xlrd  
Running setup.py
(path:c:\users\4918~1\appdata\local\temp\pip_build_┬ырфшёырт\xlrd\setup.py) egg_info for package xlrd

Cleaning up... Exception:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\install.py", line 274, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl e=self.bundle)
  File "C:\Python27\lib\site-packages\pip\req.py", line 1220, in prepare_files
    req_to_install.assert_source_matches_version()
  File "C:\Python27\lib\site-packages\pip\req.py", line 460, in assert_source_matches_version
    % (display_path(self.source_dir), version, self))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 55: ordinal  not in range(128)

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in <module>
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 185, in main
    return command.main(cmd_args)
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 70: ordinal  not in range(128)

我猜原因是 Windows 用户名中的西里尔字母,但对此无能为力。是否存在任何好的解决方案(没有创建新用户或类似的东西)?找不到答案。谢谢!

4

1 回答 1

0

我不经常使用 unicode(尤其是在我的用户名中),但看起来你的用户名是正确的。第一个例外是尝试使用包含您的非 ascii 用户名的路径格式化 ascii 字符串,它会引发异常。您可以通过在解释器中执行以下操作来获得相同的结果:

print "%s" % (u"Users\Владислав",)

我做了一点谷歌搜索,并认为您可能会从这个问题/答案中得到一些帮助:pip install selenium 出现问题

要点是您的操作系统或终端可能设置为“ascii”作为默认编码。该解决方案可能涉及编辑您的 Windows 注册表,因此请小心。另请注意,您可以通过执行以下操作检查您在 python 中的默认编码:

import sys
sys.getdefaultencoding()

编辑

我现在不在我的 Windows 机器上,所以我不确定应该在哪里设置,但是引用的答案之一说:

它看起来像是我的操作系统上的语言环境问题。必须将全局 LANG 环境变量覆盖为 LANG="en_US.UTF-8"。

于 2014-06-11T14:46:07.640 回答