UnicodeDecodeError:' ascii'编解码器不能解码位置7中的字节0xc7:序数不在范围内(128)

时间:2017-10-22 07:52:44

标签: python django pip

在提出这个问题之前,我搜索了SO,找到了几个相关的链接:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128), regarding reading in files

但它们对我的帖子没有用,所有这些都是关于程序的,但我的是用于安装。

安装点子后,查看点子列表:

C:\Users\中jin>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (28.8.0)

当我安装django使用pip时,我收到了以下错误:

C:\Users\中jin>pip install django
Collecting django
Exception:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Python27\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "C:\Python27\lib\site-packages\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "C:\Python27\lib\site-packages\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "C:\Python27\lib\site-packages\pip\download.py", line 880, in _download_http_url
    file_path = os.path.join(temp_dir, filename)
  File "C:\Python27\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 7: ordinal not in range(128)

修改-1

我在Windows10和python 2.7。

1 个答案:

答案 0 :(得分:1)

我怀疑您的临时目录在实际路径中包含非ASCII 7位字符。

如果您在Windows上,请确保将环境变量%TEMP%设置为仅使用其完整路径的目录,A-Za-z0-9范围内的值不带重音字符,符号等等。

注意

在Windows 10和python 2.7.13上,我刚刚测试并得到了:

> pip install django
Collecting django
  Downloading Django-1.11.6-py2.py3-none-any.whl (6.9MB)
    100% |################################| 7.0MB 152kB/s
Requirement already satisfied: pytz in c:\python27\lib\site-packages (from django)
Installing collected packages: django
Successfully installed django-1.11.6
> pip --version
pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)

<强> BUT

> mkdir Témp
> set TEMP=.\Témp
> pip install django
Collecting django
Exception:
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\python27\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "c:\python27\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "c:\python27\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "c:\python27\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "c:\python27\lib\site-packages\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "c:\python27\lib\site-packages\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "c:\python27\lib\site-packages\pip\download.py", line 880, in _download_http_url
    file_path = os.path.join(temp_dir, filename)
  File "c:\python27\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 31: ordinal not in range(128)