共计 2203 个字符,预计需要花费 6 分钟才能阅读完成。
筹备工作
1、创立用户和配置环境参数
(1)、创立用户组和创立所需目录
[root@python ~]# groupadd python_env
[root@python ~]# useradd -d /home/python_env -g python_env -m python_env
[root@python ~]# chmod 755 /home/python_env
[root@python ~]# mkdir -p /home/python_env/operation_workspaces
[root@python ~]# mkdir -p /home/python_env/software
[root@python ~]# mkdir -p /home/python_env/yunwei
[root@python ~]# mkdir -p /home/python_env/virtual_environment
[root@python ~]# mkdir -p /data/python_env/yunwei_platforms
[root@python ~]# chown -R python_env:python_env /data/python_env
[root@python ~]# chown -R python_env:python_env /home/python_env
(2)、通过 yum 装置必要依赖
[root@python ~]# yum install -y gcc* zlib* openssl-devel
切换到普通用户, 编译装置 python
1、下载
https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
2、部署
(1)、解压源码包并编译装置
[python_env@python ~]$ tar -zxvf $HOME/software/Python-3.6.5.tgz
[python_env@python ~]$ cd $HOME/software/Python-3.6.5
[python_env@python software/Python-3.6.5]$ ./configure --prefix=$HOME/python3.6.5 --enable-shared --enable-loadable-sqlite-extensions
[python_env@python ~]$ make && make install
(2)、装置实现后解决找不到 libpython3.6m.so.1.0 的问题
[python_env@python ~]$ $HOME/python3.6.5/bin/python3
/home/python_env/python3.6.5/bin/python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory
[python_env@python ~]$ echo "export LD_LIBRARY_PATH=\"$HOME/python3.6.5/lib:\$LD_LIBRARY_PATH\"" >> $HOME/.bashrc
[python_env@python ~]$ echo "export PATH=\"$HOME/python3.6.5/bin:\$PATH\"" >> $HOME/.bashrc
[python_env@python ~]$ source $HOME/.bashrc
[python_env@python ~]$ $HOME/python3.6.5/bin/python3
Python 3.6.5 (default, Jan 6 2022, 15:53:24)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
(3)、通过创立软链接替换以前的 python 环境
[python_env@python ~]$ pip -V
bash: pip: command not found...
[python_env@python ~]$ python -V
Python 2.7.5
[python_env@python ~]$ ln -s $HOME/python3.6.5/bin/python3 $HOME/python3.6.5/bin/python
[python_env@python ~]$ ln -s $HOME/python3.6.5/bin/pip3 $HOME/python3.6.5/bin/pip
[python_env@python ~]$ pip -V
pip 9.0.3 from /home/python_env/python3.6.5/lib/python3.6/site-packages (python 3.6)
[python_env@python ~]$ python -V
Python 3.6.5
装置 python 虚拟环境
# 创立在以后门路下
[python_env@python ~]$ python -m venv < 虚拟环境名称 >
# 创立在其余门路下,请留神权限问题,仅可在以后用户下的任意门路创立
[python_env@python ~]$ python -m venv < 绝对路径 >/< 虚拟环境名称 >
正文完