赞
踩
此文不需要前言,请从正文开始
开始搭建 |
默认大家都是有一定docker基础的,没有的话建议去花个20分钟学一下基础知识。相对于配置cuda来说,我觉得pytorch还是更简单一些。因此这里以官方的nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04
为基础,构建pytorch深度学习环境。你可以根据自己的需求选择合适的版本,地址如下:cuda官方docker镜像地址,python可以选择官方纯净版,好处是小,坏处是什么都得自己配置。也可以选择conda,好处是省心,坏处是比较大
docker pull nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04
下载完成后使用docker images
确认镜像信息。
docker run -it --name pytorch1.12.1-cuda10.2 nvidia/cuda:10.2-cudnn8-runtime-ubuntu18.04 /bin/bash # 这里镜像名称可以使用ID号,为了更清晰这个使用名称
PS: 一般创建运行后就会直接进入容器,如果没有,先使用
docker ps -a
查看容器信息,然后使用docker exec --it 容器ID /bin/bash
进入容器内部。
运行以下命令更新系统和安装基础包
apt update
apt install -y wget build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev liblzma-dev
apt clean
rm -rf /var/lib/apt/lists/*
这里可能出现的报错:
W: GPG error: https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu1804/x86_64 > InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A4B469963BF863CC E: The repository 'https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
- 1
- 2
- 3
- 4
解决办法:
- 1、获取gpg公钥
gpg --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
- 1
- 2、导出公钥,加入到 apt 信任密钥
gpg --export --armor A4B469963BF863CC | apt-key add -
- 1
- 然后再运行上面的命令即可
这里为了清晰的知道文件在哪,先新建临时目录,然后进入到目录下下载python源码包,再编译安装。
mkdir /temp
cd temp
wget https://www.python.org/ftp/python/3.7.13/Python-3.7.13.tgz
tar -xvf Python-3.7.13.tgz
cd Python-3.7.13
./configure --prefix=/usr/local/python3.7 --enable-optimizations
./configure --enable-optimizations
make -j8
make install
ln -s /usr/local/python3.7/bin/python3.7 /usr/bin/python3.7
ln -s /usr/local/python3.7/bin/pip3.7 /usr/bin/pip3
下载地址:https://repo.anaconda.com/archive/index.html
这里我以2021.05版本为例:
wget -c https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
# 安装
bash Anaconda3-2021.05-Linux-x86_64.sh
然后一直按enter直到出现需要输入yes。输入yes后会提示你安装路径
Anaconda3 will now be installed into this location:
/root/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/anaconda3] >>>
这里可以填个自己的路径,记录一下,或者默认的也可以,按enter继续。
初始化,输入yes。这里也可以看到安装路径。
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
然后会提示安装完成。
export PATH=~/anaconda3/bin:$PATH # 添加环境变量
source ~/.bashrc # 刷新bashrc
这里的export PATH填的是conda的bin文件地址。默认地址可以填上面那个到这里可以输入python和conda list查看是否安装成功。
vi ~/.condarc
channels: - http://mirrors.aliyun.com/anaconda/cloud/stackless - https://mirrors.aliyun.com/anaconda/cloud/simpleitk - https://mirrors.aliyun.com/anaconda/cloud/rdkit - https://mirrors.aliyun.com/anaconda/cloud/rapidsai - https://mirrors.aliyun.com/anaconda/cloud/qiime2 - https://mirrors.aliyun.com/anaconda/cloud/pyviz - https://mirrors.aliyun.com/anaconda/cloud/pytorch3d - https://mirrors.aliyun.com/anaconda/cloud/pytorch-test - https://mirrors.aliyun.com/anaconda/cloud/pytorch - https://mirrors.aliyun.com/anaconda/cloud/psi4 - https://mirrors.aliyun.com/anaconda/cloud/plotly - https://mirrors.aliyun.com/anaconda/cloud/omnia - https://mirrors.aliyun.com/anaconda/cloud/ohmeta - https://mirrors.aliyun.com/anaconda/cloud/numba - https://mirrors.aliyun.com/anaconda/cloud/msys2 - https://mirrors.aliyun.com/anaconda/cloud/mordred-descriptor - https://mirrors.aliyun.com/anaconda/cloud/menpo - https://mirrors.aliyun.com/anaconda/cloud/matsci - https://mirrors.aliyun.com/anaconda/cloud/intel - https://mirrors.aliyun.com/anaconda/cloud/idaholab - https://mirrors.aliyun.com/anaconda/cloud/fermi - https://mirrors.aliyun.com/anaconda/cloud/fastai - https://mirrors.aliyun.com/anaconda/cloud/dglteam - https://mirrors.aliyun.com/anaconda/cloud/deepmodeling - https://mirrors.aliyun.com/anaconda/cloud/conda-forge - https://mirrors.aliyun.com/anaconda/cloud/caffe2 - https://mirrors.aliyun.com/anaconda/cloud/c4aarch64 - https://mirrors.aliyun.com/anaconda/cloud/bioconda - https://mirrors.aliyun.com/anaconda/cloud/biobakery - https://mirrors.aliyun.com/anaconda/cloud/auto - https://mirrors.aliyun.com/anaconda/cloud/Paddle - https://mirrors.aliyun.com/anaconda/pkgs/r - https://mirrors.aliyun.com/anaconda/pkgs/msys2 - https://mirrors.aliyun.com/anaconda/pkgs/main - https://mirrors.aliyun.com/anaconda/pkgs/free show_channel_urls: true ssl_verify: true allow_conda_downgrades: true
最后按esc,输入:wq
保存退出。
mkdir ~/.pip
cd ~/.pip/
vi pip.conf
然后输入
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
pytorch安装相对很简单
pip list/conda list
查看是否有torch包,使用以下命令验证是否安装成功。import torch
print(torch.__version__)
Pytorch Docker镜像构建教程(不同系统、CUDA、Python版本)
docker容器安装TensorFlow_gpu 版本遇到的坑。。。
Ubuntu18.04安装python3.7
27 | Ubuntu18.04.5 安装python3.7及卸载
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。