攜手創作,共同成長!這是我參與「掘金日新計劃 · 8 月更文挑戰」的第4天,點擊查看活動詳情
聽說最近Pytorch支持MacBook M1Running on the chip is accelerated,我想在MacBook上試一下,結果在使用pip安裝時,The speed has been slow,And it always reports a network error and terminates in the middle of the download.Tried several times without success,終於使用pipThe issue was resolved after replacing the mirror,特此記錄.
筆者使用的是MacBook Pro M1version for laptops.之前Pytorch一直不支持M1Chip acceleration,I heard from a classmate recently that this problem seems to be solved.Check out the official website today,確實有了Mac版本的Pytorch.
於是,通過使用PytorchOfficially recommended command,利用pip進行安裝.
(hfai) [email protected] resnet % pip3 install torch torchvision torchaudio
Collecting torch
Downloading torch-1.12.0-cp38-none-macosx_10_9_x86_64.whl (137.6 MB)
━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 24.2/137.6 MB 290.3 kB/s eta 0:06:31
ERROR: Exception:
Traceback (most recent call last):
File "/Users/jiexing/opt/anaconda3/envs/hfai/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 435, in _error_catcher
yield
……
File "/Users/jiexing/opt/anaconda3/envs/hfai/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py", line 440, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
復制代碼
The result is shown above,Every time I download less than half of the time, I get an error:pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
經過在網上查找資料,Found out that the problem is due to pipThe default mirror library is abroad,This results in slow and unstable access.而且,由於torchThis library file is relatively large,It increases the risk of network problems caused by file downloads.
解決方法也很簡單,我之前在CSDN發表過一篇關於conda和pipChange the blog of Tsinghua mirror,It is transported here.
首先打開Anaconda Prompt,切換到自己的虛擬環境.之後分別輸入以下三條命令執行:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
復制代碼
然後在使用condaThe Tsinghua mirror will be used when downloading and installing the package,速度會快很多.比如:
conda install matplotlib=2.2.3
復制代碼
在使用pip installThe command can be followed by parameters-i pypi.tuna.tsinghua.edu.cn/simple,so in this…
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple matplotlib==2.2.4
復制代碼
But this only works this time,It would be more troublesome to do this every time.
在Windows環境下,可以直接在當前用戶的目錄(比如我的目錄就是C:\User\Glamour)下新建一個pip目錄,在裡面新建一個pip.ini文件,寫入如下內容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
復制代碼
保存即可.之後使用pipMuch faster when installing the package.
Back to the problem encountered today,我在pip install [name]
後加上-i https://pypi.tuna.tsinghua.edu.cn/simple
After the parameters are perfectly solved
(hfai) [email protected] resnet % pip3 install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
……
Installing collected packages: torch, pillow, torchvision, torchaudio
Successfully installed pillow-9.2.0 torch-1.12.0 torchaudio-0.12.0 torchvision-0.13.0
復制代碼
In addition to the Tsinghua mirror source,There are also some well-known mirror sources in China, such as Ali mirror sources,HKUST mirror source, etc,its specific list(不完全統計)如下:
This blog mainly introduces how toconda和pipUse Tsinghua mirror for stabilization,快速的python包安裝,通過使用-iThe parameters can flexibly set the download address of the package,非常方便.最後,This article also gives some other package download addresses other than Tsinghua mirrors that can be used flexibly.