python3、pip 源码安装

源码安装 python3

  1. 下载python包:(华为镜像源):https://mirrors.huaweicloud.com/python/

  2. 解压:tar -xzvf Python-3.7.16.tgz

  3. 更新系统包

    1. 包管理用具为 apt-get

      apt-get update

      apt-get install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev

    2. 包管理工具为:yum

      yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

  4. cd Python-3.7.16

  5. 生成 Makefile:./configure --prefix=/usr/local/python3 --enable-shared

  6. 编译:make && make install

  7. 测试:./python -V

  8. 错误:

    1. 3.12 版本在执行 python 时,报错 “./python: error while loading shared libraries: libpython3.12.so.1.0: cannot open shared object file: No such file or directory”

      原因:生成 makefile 时 ./configure --prefix=/usr/local/python3 --enable-shared 开启了–enable-shared 导致的。

      解决方法:将源码包里的该文件复制到usr/lib64/里 cp libpython3.12.so libpython3.12.so.1.0 /usr/lib64/

安装 pip

  1. 下载:curl -O https://bootstrap.pypa.io/get-pip.py
  2. 安装:./python3 get-pip.py
posted @ 2023-03-23 10:04  aaron_agu  阅读(160)  评论(0编辑  收藏  举报