4

我正在 Python 2.7.2 下的 virtualenv 中安装一个为 pip 打包的 egg。egg 有 16 个要求,其中之一(pycryptopp 0.5.29)已知在 gcc-4.6 中失败,因此必须使用 4.5 进行编译。系统同时安装了 gcc-4.6(默认)和 gcc-4.5。

如何配置/破解 pip install 来专门构建这个包?(或者我只是在安装此软件包时暂时混淆链接 /usr/bin/gcc )

我是否需要清理它破坏的现有 (virtualenv)/build 目录,如果需要,如何?

(我已经阅读了 pip 文档并搜索了 SO + SU)

4

3 回答 3

7

No need to fiddle around with symlinks here. On most Linux systems you can set the compiler to use with the CC env var. In case of pycryptopp and pip the following might help:

$ CC=/usr/bin/gcc-4.5 pip install pycryptopp

given that you have GCC 4.5 installed in that location. This worked fine for me on Ubuntu 11.10 (oneiric) with packages gcc-4.5 and g++-4.5 installed.

于 2012-01-20T12:47:30.103 回答
1

(我将问题重新命名为“如何使用 pip install 其中一项要求必须使用 gcc-4.5 编译?”)

1) 正确的方法是使用链接到 libcryptopp的“--disable-embedded-cryptopp”进行构建。有些人报告运行时问题,但它适用于我。

pip install --install-option="--disable-embedded-cryptopp" pycryptopp

2.)我使用的一个真正丑陋的解决方法(ulif 有用地指出,可以通过使用 CC=.. 来避免)是专门为问题包调用 pip install ,并暂时混淆到 gcc 的链接。

pushd /usr/bin; sudo rm gcc-4.6; ln -s gcc-4.5 gcc; popd;
pip install pycryptopp
pushd /usr/bin; sudo rm gcc-4.5; ln -s gcc-4.6 gcc; popd;

这不好的进一步原因是:它需要 root 访问权限并弄乱 gcc 二进制文件的链接。它当然不能是 Makefile'd。

于 2011-10-20T23:05:30.163 回答
1

添加此内容以扩展现有的良好答案;如果您使用基于 apt 的发行版,例如Ubuntuor Debian,您可以执行以下操作:

第 1 步:安装您需要的 gcc/g++ 版本

sudo apt install gcc-7 gcc-8 g++-7 g++-8

第 2 步:将 gcc/g++ 版本安装到操作系统的“替代”系统中:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 80

第 3 步:选择您的活动 gcc/g++ 版本

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

它会在每种情况下询问您想要哪个版本,或使用您提供的“重量”为您自动选择:

Selection    path               Priority    Status
--------------------------------------------------------------------
* 0          /usr/bin/gcc-8     80          auto mode
  1          /usr/bin/gcc-8     80          manual mode
  2          /usr/bin/gcc-7     70          manual mode

Press ENTER to maintain, or type the selection number to the corresponding version.

提示:如果要删除版本,只需使用以下命令:

sudo update-alternatives --remove gcc /usr/bin/gcc-7

您仍将使用 root/sudo 访问权限来执行此操作,但它比处理手动删除/创建链接或在命令行上指定环境变量要干净得多。这是在基于 arpt 的发行版中为各种事物选择版本的推荐方法。

于 2020-02-29T01:13:03.353 回答