Question

I am installing an egg packaged for pip, inside my virtualenv, under Python 2.7.2. The egg has 16 requirements, one of which (pycryptopp 0.5.29) is known to fail with gcc-4.6 and hence must be compiled with 4.5. The system has both gcc-4.6 (default) and gcc-4.5 installed.

How do I configure/hack pip install to build this package specially? (or do I just temporarily kludge the link /usr/bin/gcc while installing this package)

Do I need to clean up the existing (virtualenv)/build directory where it broke, and if so how?

(I already read the pip documentation and searched SO + SU)

Was it helpful?

Solution

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.

OTHER TIPS

(I retitled the question from "How to use pip install where one requirement must be compiled with gcc-4.5?")

1) The correct method is to build with "--disable-embedded-cryptopp" which links to libcryptopp. Some people report runtime issue but It Works For Me.

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

2.) A truly ugly workaround which I used (and which ulif helpfully points out can be obviated by using CC=.. ) is to invoke pip install specifically for the problem package, and temporarily kludge the link to 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;

Further reasons this is bad: it requires root access and messing with the link to gcc binary. It certainly can't be Makefile'd.

Adding this for completeness to extend upon the existing good answers; if you are on apt based distribution such as Ubuntu or Debian, you can do the following:

Step 1: Install the versions of gcc/g++ you need

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

Step2: Install your gcc/g++ versions into "alternatives" system of your OS:

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

Step 3: Select your active gcc/g++ versions

sudo update-alternatives --config gcc

sudo update-alternatives --config g++

It will in each case ask you which version you want, or use the "weight" you provided to select automatically for you:

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.

TIP: If you want to delete a version, simply use this:

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

You will still use root/sudo access to do this, but it is much cleaner than dealing with manually deleting/creating links, or specifying environment variables on the commandline. It is the recommended way of selecting versions for all kinds of things in arpt based distributions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top