linux 下源码编译并安装 Python

430 阅读1分钟

python 3.9国内源 https://mirrors.huaweicloud.com/python/3.9.0/

  • 下载并解压
    wget https://mirrors.huaweicloud.com/python/3.9.0/Python-3.9.0.tar.xz  
    tar -xvf Python-3.9.0.tar.xz 
    
  • 切换到解压包下
    cd Python-3.9.0 
    
  • configure并编译
    # 当然也可以不在build中间目录下,直接./configure
    mkdir build  
    cd build 
    ../configure    
    make -j8 && make install   
    
  • 注意,此次编译会将python 2.7安装在/usr/bin下,而python 3.9 会安装在/usr/local/bin, 所以在使用命令行时要指定
    # 因为 python3 是 python3.9 的软链接
    python3 xx
    
  • 查看版本号
    python3 -V
    
  • 预装工具
    # python 安装工具和环境生成工具
    pip install pyinstaller  
    pip install virtualenv