1. 程式人生 > >Debian 9 編譯Python

Debian 9 編譯Python

end prim readline sse apt-get decide 共享 read 啟用

Debian 9 編譯Python

參考網址:

  1. https://solarianprogrammer.com/2017/06/30/building-python-ubuntu-wsl-debian/
  2. https://www.cnblogs.com/freeweb/p/5181764.html
  3. https://docs.python.org/3/using/unix.html#on-linux

    準備工作

  4. 配置編譯環境
    • 安裝gcc, make, g++
    • 安裝GCC toolchain

      apt-get install build-essential

    • 安裝編譯庫

      libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev

  5. 編譯參數
    • 設置編譯後文件安裝位置,默認/usr/

      prefix --- Python模塊位置, ${prefix}/lib/pythonversion
      exec_prefix --- Python執行位置,${exec_prefix}/bin/python3
      默認prefix與exec_prefix相同

    • 使用優化的設置進行編譯

      configure --enable-optimizations

    • 啟用Link Time Optimization

      --with-lto, LTO當構建最終的可執行文件或共享庫以獲得額外的性能收益時,LTO利用最近編譯器工具鏈的優勢,跨越任意的.o文件邊界進行優化。

  6. 編譯安裝
    • 並存安裝

      If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using make install. Install all other versions using make altinstall.

    • 安裝

      make -j n n為指定的編譯線程數
      make install

Debian 9 編譯Python