python安装

python安装

python3.6.12
python库
zlib1.3
openssl-1.1.1

1. 前置安装

python安装依赖于gcc、openssl-devel、zlib-devel
实际环境存在gcc环境,仅安装openssl-devel、zlib-devel
前置安装使用root用户操作

1.1 安装zlib

1
2
3
4
5
6
#下载zlib离线包
#解压
tar -xvf zlib-1.3.tar.gz
#编译
./configure
make && make install

1.2 安装openssl-1.1.1

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
26
27
#下载openssl离线包(版本尽量为1.1.X)
#解压
tar -xvf openssl-1.1.1n.tar.gz
#编译
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install

#配置环境变量
vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/openssl/bin:$PATH

source ~/.bashrc
````

## 2. python安装

````bash
#下载python
#解压
tar -xvf Python-3.6.12.tgz
cd Python-3.6.12
#编译和安装:
#执行以下命令进行编译和安装:
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-ssl
make && make install

报错查看

/usr/bin/install: cannot create regular file /usr/local/bin/python3.6: Permission denied make: *** [altbininstall] Error 1

1
2
3
#执行
./configure --prefix=$HOME/py26
make install

If you want a release build with all stable optimizations active (PGO, etc), please run ./configure --enable-optimizations

1
2
#请执行
./configure --enable-optimizations

验证安装

1
python3 --version

其他用户未配置环境变量可能无法使用Python,需要手动配置

1
2
3
4
5
6
#其他用户添加python
vi ~/.bashrc
#添加环境变量
export PATH="/usr/local/python3/bin:$PATH"
#刷新配置文件
source ~/.bashrc

3. 安装第三方库

安装可通过python安装或pip安装

3.1 pip安装

1
2
3
4
5
6
7
8
pip3 install cryptography-3.4.8.tar.gz
pip3 install gbase-connector-python-3.0.1.tar.gz
pip3 install urllib3-1.26.18.tar.gz
pip3 install charset-normalizer-2.0.12.tar.gz
pip3 install certifi-2023.7.22.tar.gz
pip3 install idna-3.4-py3-none-any.whl
pip3 install pycparser-2.21-py2.py3-none-any.whl
pip3 install requests-2.31.0.tar.gz

3.2 python安装

1
2
3
4
5
#以requests模块举例
#解压文件后转入目录执行命令`python setup.py install`
tar -xvf requests-2.31.0.tar.gz
cd requests-2.31.0
python3 setup.py install

3.3 查看安装

1
pip3 list