python用pip装第三方库numpy时报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordi

2023-05-16

python用pip装第三方库numpy时一直报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

pip install numpy

Collecting numpy
Exception:
Traceback (most recent call last):
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "E:\Python27\lib\site-packages\pip-9.0.1-py2.7.egg\pip\download.py", line 880, in _download_http_url
    file_path = os.path.join(temp_dir, filename)
  File "E:\Python27\lib\ntpath.py", line 85, in join
    result_path = result_path + p_path

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

网上查了方法,方法1:

很多说在文件开头加入三行:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

但是装第三方库并不是运行自己写的程序,所以不能加。

方法2:打开python27/Lib文件夹下的mimetypes.py文件,在253行左右,在default_encoding=sys.getdefaultencoding()前加三行:

if sys.setdefaultencoding()!='gbk':
reload(sys)
sys.setdefaultencoding('gbk')

default_encoding=sys.getdefaultencoding()

但是还是同样的问题。

方法3:打开python27/Lib文件夹下的site.py文件,修改defsetencoding()方法:

defsetencoding()
if 0:

把if 0改为if 1.但还是没有解决问题。

方法4:打开python27/Lib文件夹下的site.py文件,在文件开头加入三行:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

顺利解决问题。分享给大家。


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python用pip装第三方库numpy时报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordi 的相关文章

随机推荐