示例环境部署(CentOS)

使用环境:Python3.10

修改yum源

#未安装wget,可以yum装下
yum install -y wget


mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo

卸载ssl

yum remove -y openssl

下载OpenSSL

Python3高版本在centos系统编译需要使用OpenSSL版本1.1.1的源码使用wget下载

cd /opt
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz --no-check-certificate

解压编译openssl

tar -zxf openssl-1.1.1n.tar.gz
cd openssl-1.1.1n
# 安装依赖
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y perl-CPAN

编译安装

./config --prefix=/usr/local/openssl
make -j 2
make install

添加到动态库

ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v

验证

openssl version

下载python3.10.12

# python安装目录
mkdir /usr/local/python3/
cd /usr/local/python3/
#下载python包
wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz

安装python的依赖包

yum install epel-release
yum install -y gcc patch libffi-devel python-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel db4-devel 

编译安装

tar -zxf Python-3.10.12.tgz
cd Python-3.10.12
# 配置ssl
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto

make clean 
make -j && make install

4.链接

# 创建
ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3

修改镜像源

mkdir /root/.pip
vim /root/.pip/pip.conf

将如下文件存入

[global]
trusted-host = mirrors.aliyun.com
index-url = https://mirrors.aliyun.com/pypi/simple

创建python3.10虚拟环境并安装相关包

python3 -m venv py3

# 更新pip
pip3 install --upgrade pip
source py3/bin/activate

pip install pandas matplotlib xgboost catboost lightgbm optuna seaborn

# 安装机器学习库
pip install -U scikit-learn

安装jupyter

pip install jupyter

安装成功之后运行notebook

jupyter notebook --allow-root --no-browser

在本地主机上建立隧道远程连接到远程服务器(cmd中运行)

ssh -N -f -L localhost:8888:localhost:8888 (用户)@(远程服务器IP)
# 输入远程服务器的密码
# 此时数据仅在远程服务器中,并未被拉到本地

在本地主机浏览器中直接访问localhost:8888即可访问远程文件系统并进行测试代码

image-20230619160416723

最后修改:2024 年 01 月 12 日
反正没人给,你也爱给不给吧。