您好,登錄后才能下訂單哦!
小編給大家分享一下pip中install報錯的解決方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
解決方法:1、ReadTimeoutError,在pip安裝所在文件夾路徑下,創造python文件;2、UnicodeDecodeError,在Python27\Lib\site-packages下建個sitecustomize.py文件。
本教程操作環境:windows7系統、python3版、Dell G3電腦。
pip install 報錯問題解決
相關免費學習推薦:python視頻教程!
有時在用pip install命令安裝python庫時出現紅字報錯
1.報錯:ReadTimeoutError: HTTPSConnectionPool(host=’pypi.python.org’, port=443): Read timed out.
Downloading xgboost-0.6a2.tar.gz (1.2MB) 48% |███████████████▋ | 583kB 47kB/s eta 0:00:13Exception: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 882, in _download_http_url _download_url(resp, link, content_file, hashes) File "c:\python27\lib\site-packages\pip\download.py", line 603, in _download_url hashes.check_against_chunks(downloaded_chunks) File "c:\python27\lib\site-packages\pip\utils\hashes.py", line 46, in check_against_chunks for chunk in chunks: File "c:\python27\lib\site-packages\pip\download.py", line 571, in written_chunks for chunk in chunks: File "c:\python27\lib\site-packages\pip\utils\ui.py", line 139, in iter for x in it: File "c:\python27\lib\site-packages\pip\download.py", line 560, in resp_read decode_content=False): File "c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 357, in stream data = self.read(amt=amt, decode_content=decode_content) File "c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 324, in read flush_decoder = True File "c:\python27\lib\contextlib.py", line 35, in __exit__ self.gen.throw(type, value, traceback) File "c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\response.py", line 246, in _error_catcher raise ReadTimeoutError(self._pool, None, 'Read timed out.') ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
錯誤原因:連不上pip的源,下載依賴包失敗
解決(推薦):在pip安裝所在文件夾路徑下,創造python文件(.py)
import os ini="""[global] index-url = https://pypi.doubanio.com/simple/ [install] trusted-host=pypi.doubanio.com """ pippath=os.environ["USERPROFILE"]+"\\pip\\" if not os.path.exists(pippath): os.mkdir(pippath) with open(pippath+"pip.ini","w+") as f: f.write(ini)
在cmd上運行這個.py文件即可
之后再用pip install安裝指令下載速度會非常快
2.報錯:UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd3 in position 7: ordinal not in range(128)
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)
報錯原因:pip安裝Python包會加載目錄包含中文字符,ascii不能編碼
解決:python目錄 Python27\Lib\site-packages 建一個文件sitecustomize.py
import sys sys.setdefaultencoding('gbk')
python會自動運行這個文件
以上是“pip中install報錯的解決方法”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。