编译安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 安装python3
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
python_version="3.10.6"
mkdir /opt/python3
cd /usr/local/src
wget https://www.python.org/ftp/python/${python_version}/Python-${python_version}.tgz
tar xf Python-${python_version}.tgz
cd Python-${python_version}

# 编译安装
./configure --prefix=/opt/python3 \
  --with-openssl=/opt/openssl \
  --with-openssl-rpath=/opt/openssl/lib

make -j4
make altinstall

# 安装numpy
./python3.10 -m pip install numpy

# 安装pandas
./python3.10 -m pip install pandas

# 安装statsmodels
./python3.10 -m pip install statsmodels

虚拟环境使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 安装 virtualenv(python3内置)
# pip install virtualenv
# 创建虚拟环境
python3 -m venv venv_demo
# 激活虚拟环境
source venv_demo/bin/activate
# 安装相关依赖包
python3 -m pip install PyYAML
# 查看安装的依赖包
python3 -m pip list
# 打包虚拟环境
python3 -m pip freeze > requirements.txt
# 迁移虚拟环境
python3 -m pip install -r requirements.txt
# 退出虚拟环境
deactivate
# 删除虚拟环境
rm -rf venv_demo