linux 安装 python 解释器

解释器准备

进入python官网:https://www.python.org/

点击download

image

点击Linux

image

找到你想要的版本,点击下载

image

服务器操作

将下载的文件,上传到服务器

也可以使用wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz 进行下载

解压tar -zxvf Python-3.9.6

进入解压文件夹cd Python-3.9.6

创建安装目录,个人喜好

mkdir -p /usr/local/python3.9

编译安装

./configure --prefix=/usr/local/python3.9
image

看到上图,就是编译完成了

make
make install

出现successful表示安装成功了

Looking in links: /tmp/tmpsgo6wais
Processing /tmp/tmpsgo6wais/setuptools-56.0.0-py3-none-any.whl
Processing /tmp/tmpsgo6wais/pip-21.1.3-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: The scripts pip3 and pip3.9 are installed in '/usr/local/python3.9/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.1.3 setuptools-56.0.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

检查

进入安装目录 cd /usr/local/python3.9/bin/python3.9

执行 ./python3.9 -V 能正确输出版本号,表示解释器安装成功

配置环境变量

vi /etc/profile

在最下边输入

export PYTHON_HOME=/usr/local/python3.9
export PATH=${PYTHON_HOME}/bin:$PATH

让环境变量的配置,立即生效

source /etc/profile

随便在那个目录下 执行 python3.9 -V 能正确输出版本号,表示环境变量配置成功

安装过程中,可能出现的问题

找不到zlib linux No module named 'zlib'

进入官网下载包 http://zlib.net/

或者执行命令:wget http://zlib.net/zlib-1.3.1.tar.gz

解压缩安装

tar -zxvf zlib-1.3.1.tar.gz
cd zlib-1.3.1
./configure
make && make install

回到 Python-3.9.6 目录,再次执行make && make install

找不到包 Failed to build these modules: _ctypes

image

安装libffi-devel yum install libffi-devel

回到 Python-3.9.6 目录,再次执行make && make install

posted @ 2025-04-27 15:21  darling331  阅读(139)  评论(0)    收藏  举报