docker容器中安装pytorch
前戏
官网:https://pytorch.org/get-started/locally/
去官网的目的,是查看我们需要install那几个package
发现我们只需要pip: torch torchvision torchaudio
安装
第一步:交互式进入容器
docker exec -it 容器名 bash
第二步:pip install,使用国内源安装
根据官网下载:很慢
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
使用国内源替换之
pip3 install torch torchvision torchaudio -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
具体详情如下:速度起飞
$ docker exec -it pycharm_test bash
________ _______________
___ __/__________________________________ ____/__ /________ __
__ / _ _ \_ __ \_ ___/ __ \_ ___/_ /_ __ /_ __ \_ | /| / /
_ / / __/ / / /(__ )/ /_/ / / _ __/ _ / / /_/ /_ |/ |/ /
/_/ \___//_/ /_//____/ \____//_/ /_/ /_/ \____/____/|__/
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.
To avoid this, run the container by specifying your user's userid:
$ docker run -u $(id -u):$(id -g) args...
root@05464b32beba:/tf# pip3 install torch torchvision torchaudio -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple
Collecting torch
Downloading http://pypi.doubanio.com/packages/2b/5c/14f3d5bf876d4db062e20baa933dce98ab7dde6599f462099fa2f69cc7e0/torch-1.11.0-cp38-cp38-manylinux1_x86_64.whl (750.6 MB)
|████████████████████████████████| 750.6 MB 405 kB/s
Collecting torchvision
Downloading http://pypi.doubanio.com/packages/18/8b/309116c0bdc90ac7036ca331bfec8dd3e6f7f6d00f869fe6552da096e94a/torchvision-0.12.0-cp38-cp38-manylinux1_x86_64.whl (21.0 MB)
|████████████████████████████████| 21.0 MB 10.5 MB/s
Collecting torchaudio
Downloading http://pypi.doubanio.com/packages/74/2d/899c31bc274ac49754d3964fce9f4b328bed3a277102e8f872f758f282d2/torchaudio-0.11.0-cp38-cp38-manylinux1_x86_64.whl (2.9 MB)
|████████████████████████████████| 2.9 MB 2.3 MB/s
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.8/dist-packages (from torch) (4.0.1)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.8/dist-packages (from torchvision) (9.0.0)
Requirement already satisfied: requests in /usr/local/lib/python3.8/dist-packages (from torchvision) (2.27.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from torchvision) (1.22.1)
Requirement already satisfied: charset-normalizer~=2.0.0; python_version >= "3" in /usr/local/lib/python3.8/dist-packages (from requests->torchvision) (2.0.11)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.8/dist-packages (from requests->torchvision) (2021.10.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from requests->torchvision) (1.26.8)
Requirement already satisfied: idna<4,>=2.5; python_version >= "3" in /usr/local/lib/python3.8/dist-packages (from requests->torchvision) (3.3)
Installing collected packages: torch, torchvision, torchaudio
Successfully installed torch-1.11.0 torchaudio-0.11.0 torchvision-0.12.0
WARNING: You are using pip version 20.2.4; however, version 22.0.4 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.
后记
尽管本地有md文档,其中有完整的记录,但是还是push到网站上,便于检索。
|