【问题标题】:Issue with installing Python 2.7.8 alongside 2.7.5 on RHEL 7.2在 RHEL 7.2 上安装 Python 2.7.8 和 2.7.5 的问题
【发布时间】:2016-09-17 14:55:32
【问题描述】:

我有一个安装了 Red Hat Linux 7.2 的 Amazon EC2 实例。它在系统范围内安装了 Python 2.7.5。

我已经编译了 Python 2.7.8 的替代安装(这是我在尝试复制的另一个环境中使用的)。我将使用它来创建一个 virtualenv 来启动我的 Django 应用程序。

但调用 python2.7 总是将我带到系统范围的 python 2.7.5 解释器。

我按照以下说明操作:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/

$ sudo yum groupinstall 'development tools'
$ sudo yum install  zlib-dev openssl-devel sqlite-devel bzip2-devel
$ sudo yum install wget
$ sudo wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
$ sudo yum install xz-libs
$ xz -d Python-2.7.8.tar.xz
$ tar -xvf Python-2.7.8.tar
$ cd Python-2.7.8

编辑文件 /etc/ld.so.conf 以添加该行

/usr/local/lib

$sudo /sbin/ldconfig --> make the dynamic linker aware of the change

$sudo ./configure --prefix=/usr/local  --enable-unicode=ucs4  --enable-shared
$make

我收到以下消息,但我不确定这是否与我的问题有关。

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _tkinter           bsddb185
dbm                dl                 gdbm
imageop            sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

$sudo make altinstall

$which python
/usr/bin/python ---> system wide Python 2.7.5
$which python2.7
/usr/local/bin/python2.7 ---> this should point to Python 2.7.8 that was compiled and installed.

但调用 python2.7 指向系统范围的 Python 2.7.5 解释器:

$python2.7
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2

为什么会这样?

仅供参考,我的 PATH 确实包含 /usr/local/bin。

$echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin

【问题讨论】:

    标签: python linux python-2.7


    【解决方案1】:

    参考:http://koansys.com/tech/building-python-with-enable-shared-in-non-standard-location “我可以使用“ldd”将他们的库添加到系统缓存中,只要没有任何其他相同版本的 python 需要它,它就可以工作。”

    我通过从 /etc/ld.so.conf 中删除 /usr/local/lib 并使用 -rpath 选项指定 LDFLAGS 来解决我的问题,如下所示:

    $sudo ./configure --prefix=/usr/local/python --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/python/lib"
    

    注意它是 -Wl 而不是 -W1(即小写 L 而不是数字 1)。我花了几个小时找出那个错误!感谢gcc soname unrecognized command line 指出这一点。

    $make
    $sudo make altinstall
    

    这行得通,从该路径调用 Python 解释器也可以正常工作:

    $/usr/local/python/bin/python2.7 -- version
    Python 2.7.8
    

    网络上的大多数教程都说明了如何并排安装两个不同版本的 Python,例如 Python 2.6.x 和 2.7.x 或 Python 2.7.x 和 3.3.x。

    但是,当两个安装都是 Python 2.7.x 时,如果在 /etc/ld.so.conf 中指定了自定义安装的路径,则似乎存在问题 - 可能被拾取的库属于系统默认值。 ..我仍然不明白引擎盖下发生了什么。

    我还在 .bashrc 中将 /usr/local/python/bin 添加到我的 PATH 中。

    但是,在后续安装 setuptools、pip、virtualenv 和 virtualenvwrapper 的步骤中,我仍然必须显式调用 python2.7 或 pip2.7 的完整路径,否则软件包安装在 /usr/lib/python2 中。 7/site-packages/ 而不是 /usr/local/python/lib/python2.7/site-packages。

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 2016-12-02
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多