如何手动传递用于 Python 安装的 bzip2 安装源?

ste*_*dox 5 python node.js bzip2 python-2.7

我已经解决了几个关于 Python 和 bzip2 的 StackOverflow 问题。这些对于让我进入我现在的状态非常有帮助。这是我到目前为止所做的以及我遇到的问题:

  • 没有root 访问权限,无法安装 libbz2-dev(el)
  • /usr/bin/bzip2 是 1.0.3 版
  • /usr/bin/python 是 2.4.3 版
  • GNU Stow被用来管理类似于 homebrew 工作方式的库

我需要 Python 2.7.3 与 bzip2 模块一起安装,以便从源代码正确编译 node.js。是的,我很抱歉,但我确实必须作为一个来自源头的普通用户来做这一切。

我已经从源代码安装了 bzip2,如下所示:

$ make -f Makefile-libbz2_so
$ make
$ make install PREFIX=${STOW}/bzip2-1.0.6
$ cp libbz2.so.1.0.6 ${STOW}/bzip2-1.0.6/lib/
$ cd ${STOW}/bzip2-1.0.6/lib
$ ln -s libbz2.so.1.0.6 libbz2.so.1.0
$ cd ${STOW}
$ stow bzip2-1.0.6
Run Code Online (Sandbox Code Playgroud)

在其他任何事情之前,我的 PATH 中都有 stow 的根目录,所以这导致:

$ bzip2 -V
# [...] Version 1.0.6
Run Code Online (Sandbox Code Playgroud)

这表明在我的 PATH 中使用了正确的 bzip2。

接下来,我继续从源代码编译 Python 并运行以下命令:

$ cd Python-2.7.3
$ ./configure --prefix=${STOW}/Python-2.7.3
$ make
# Complains about several missing modules, of which "bz2" is the one I care about
$ make install prefix=${STOW}/Python-2.7.3 # unimportant as bz2 module failed to install
Run Code Online (Sandbox Code Playgroud)

在源配置中告诉 Python 源安装的 bzip 1.0.6 库所在的位置的正确方法是什么,以便它将检测 bzip2 devel 标头并正确安装模块?

ste*_*dox 5

好吧,我花了几个月的时间才做到这一点,但我终于回来并设法解决了这个问题。

  • 从源安装 bzip2:

      # Upload bzip2-1.0.6.tar.gz to ${SRC}
      $ cd ${SRC}
      $ tar -xzvf bzip2-1.0.6.tar.gz
      $ cd bzip2-1.0.6
      $ export CFLAGS="-fPIC"
      $ make -f Makefile-libbz2_so
      $ make
      $ make install PREFIX=${STOW}/bzip2-1.0.6
      $ cp libbz2.so.1.0.6 ${STOW}/bzip2-1.0.6/lib/
      $ cd ${STOW}/bzip2-1.0.6/lib
      $ ln -s libbz2.so.1.0.6 libbz2.so.1.0
      $ cd ${STOW}
      $ stow bzip2-1.0.6
      $ source ${HOME}/.bash_profile
      $ bzip2 --version
      #=> bzip2, a block-soring file compressor. Version 1.0.6...
    
    Run Code Online (Sandbox Code Playgroud)
  • 从源代码安装 Python:

      # Upload Python-2.7.3.tar.gz to ${SRC}
      $ cd ${SRC}
      $ tar -xzvf Python-2.7.3.tar.gz
      $ cd Python-2.7.3
      $ export CFLAGS="-fPIC"
      $ export C_INCLUDE_PATH=${STOW}/../include
      $ export CPLUS_INCLUDE_PATH=${C_INCLUDE_PATH}
      $ export LIBRARY_PATH=${STOW}/../lib
      $ export LD_RUN_PATH=${LIBRARY_PATH}
      $ ./configure --enable-shared --prefix=${STOW}/Python-2.7.3 --libdir=${STOW}/../lib
      $ make
      $ make install prefix=${STOW}/Python-2.7.3
      $ cd ${STOW}
      $ stow Python-2.7.3
      $ source ${HOME}/.bash_profile
      $ python -V
      #=> Python 2.7.3
      $ python -c "import bz2; print bz2.__doc__"
      #=> The python bz2 module provides...
    
    Run Code Online (Sandbox Code Playgroud)

虽然从技术上讲,node.js 不是问题的一部分,但它促使我完成上述所有内容,因此我也可以包含最后几个命令,以使用源安装 Python 2.7 从源安装 node.js。 3 和 bzip2 1.0.6:

  • 从源安装node.js:

      # Upload node-v0.10.0.tar.gz to ${SRC}
      $ cd ${SRC}
      $ tar -xzvf node-v0.10.0.tar.gz
      $ cd node-v0.10.0
      $ ./configure --prefix=${STOW}/node-v0.10.0
      $ make
      $ make install prefix=${STOW}/node-v0.10.0
      $ cd ${STOW}
      $ stow node-v0.10.0
      $ source ${HOME}/.bash_profile
      $ node -v
      #=> v0.10.0
    
    Run Code Online (Sandbox Code Playgroud)