动手学深度学习——环境搭建
CentOS环境
1、更新系统源
CentOS 7 已于2024年6月30日结束维护,已无法通过系统自带源安装和更新系统文件,可更改为国内系统源来安装和更新系统文件。
-
进入/etc/yum.repos.d目录下找到 CentOS-Base.repo
-
将CentOS-Base.repo文件内容更改为阿里源、清华源、中科大源等皆可。
中科大(参考地址:CentOS - USTC Mirror Help)
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清华源
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
阿里源:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- 文件源文件更新后,执行如下命令:
yum clean all
rm -rf /var/cache/yum/
yum makecache
2、安装编译环境
yum groupinstall "Development Tools"
3、安装Python3
# 1、安装Python编译过程中需要的一些依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
# 3.7以后版本需要
yum install libffi-devel -y
yum install zlib*
# 2、创建一个空文件夹并在改文件夹下使用wget从Python的官方网站下载Python 3.8的源码(若需别的版本可以自行找到连接并更改连接)
mkdir install_python
cd install_python
wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
# 3、解压
tar xzf Python-3.8.12.tgz
# 4、进入解压目录后编译安装Python 3.8(这里使用--prefix参数安装到/usr/local/python3.8,如需别处可以自行更改)
cd Python-3.8.12
sudo ./configure --prefix=/usr/local/python3.8 --enable-optimizations
# 注意:编译时,gcc版本需要8以上
make
sudo make install
# 5、验证安装成功
/usr/local/python3.8/bin/python3.8 --version
# 6、将系统默认的python备份
mv /usr/bin/python /usr/bin/python2.7.5
# 7、更改软连接
# (可选)ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python
ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python3
# 8、验证
python --version
4、安装miniconda
# miniconda官网:https://docs.conda.io/projects/miniconda/en/latest/miniconda官网:https://docs.conda.io/projects/miniconda/en/latest/
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
5、进入base会话
bash
6、使用pip安装jupyter、d2l、torch、torchvison
python3 -m pip install jupyter d2l torch torchvision
这一步安装会有点长,也可以自行换清华源或者其他国内的镜像,可能会快一点。
注意: 安装d2l是可能会报错,可指定版本安装:
pip install d2l==0.17.0
7、安装李沐老师的jupyter记事本
wget https://zh-v2.d2l.ai/d2l-zh.zip
8、安装zip
yum install zip
9、解压d2l-zh.zip
unzip d2l-zh.zip
- 使用ls查看当前目录,解压出来有三个版本mxnet、pytorch、tensorflow,这里我们使用pytorch版本。
10、从github克隆ppt
git clone https://github.com/d2l-ai/d2l-pytorch-slides
11、启动jupyter
jupyter notebook --allow--root
这里提示成功启动了 Jupyter Notebook 服务器,并且服务器正在运行中。请注意,由于服务器的环境中没有可运行的浏览器,因此会显示错误信息。
我们可以通过以下链接之一访问 Jupyter Notebook 服务器:
http://localhost:8888/tree?token=....
http://127.0.0.1:8888/tree?token=....
请复制其中一个链接并在浏览器中打开,即可开始使用 Jupyter Notebook。如果您想停止服务器,请使用 Ctrl-C 终止命令两次来确认关闭服务器。
12、将远端的jupyter映射到本地
在本地主机上打开终端并执行以下命令,进行端口转发:
ssh -NL 8888:localhost:8888 username@remote_host
# 其中,username 是远程主机的用户名,remote_host 是远程主机的地址
然后就可以在本地浏览器访问刚才的链接了
13、安装rise插件
rise 是一个用于创建幻灯片的 Jupyter Notebook 扩展,它可以将 Jupyter Notebook 转换为交互式幻灯片演示。
pip install rise