pip install 问题
C:\Users\用户>pip install NumPy
Collecting NumPy
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 0xd3 in position 7: ordinal not in range(128)
---------------------
找了一个python大神,解决了一下午都没发现具体是啥原因,软件下载了再卸载,在换版本在安装还是不行,不得已从D盘安装到了C盘,今天早上无意间看了 :https://blog.csdn.net/u013567842/article/details/68955214 这篇文章,才发现问题,感谢这个博主
解决办法:
原因是pip安装Python包会加载我的用户目录,我的用户目录恰好是中文的,ascii不能编码。 解决办法是: python目录 Python27\Lib\site-packages 建一个文件sitecustomize.py 内容写: import sys sys.setdefaultencoding('gbk') python会自动运行这个文件。