18

I am currently trying to install pycrypto and when I execute python setup.py build I receive this following error:

cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/_fastmath.o -lgmp -o build/lib.macosx-10.9-intel-2.7/Crypto/PublicKey/_fastmath.so
ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'cc' failed with exit status 1

I've already tried reinstalling the command line tools and removing old instances of Xcode.

Any help would be great thanks

karthikr
  • 87,486
  • 24
  • 182
  • 182

14 Answers14

34

This worked for me. (Should work if you are on Xcode 5.1)

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pycrypto
idmean
  • 13,418
  • 7
  • 47
  • 78
domino
  • 1,899
  • 1
  • 20
  • 29
  • For others; if using buildout you can use the [environment] tag, or simply run python bootstrap.py && ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future bin/buildout – Doug Apr 30 '14 at 03:22
  • not working. `clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1` – andilabs May 20 '14 at 09:45
12

This did it for me:

  sudo port install gmp
  sudo ln -s  /opt/local/lib/libgmp.dylib  /usr/lib/libgmp.dylib  
  ARCHFLAGS=-Wno-error CFLAGS=-I/opt/local/include sudo -E pip install pycrypto
radiofrequency
  • 853
  • 8
  • 19
  • Using the last line worked for me, even without the first two. – Ari May 12 '14 at 22:21
  • 2
    You can use `LDFLAGS=-L/opt/local/lib` instead of linking libgmp. Not sure if it's actually safer, since you might link with other libs from /opt/local though. – remram Nov 06 '14 at 04:39
  • what worked for me on El Capitan was `brew install gmp` and `ARCHFLAGS=-Wno-error CFLAGS=-I/opt/local/include LDFLAGS=-L/usr/local/Cellar/gmp/6.1.0/lib/ pip install pycrypto` (you might need to change gmp dir version) – fjsj May 09 '16 at 16:39
9

I ran into the same issue and was able to fix it by installing gmp:

brew install gmp

Then I nuked my build directory and started over with the pycrypto install and it succeeded.

This also fixes the warning message during pycrypto's configure script:

warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath

See related question.

Community
  • 1
  • 1
Chris Eldredge
  • 2,891
  • 2
  • 21
  • 33
8

On Yosemite:

CC=clang sudo -E pip install pycrypto
thinkski
  • 1,236
  • 1
  • 13
  • 23
  • `Requirement already satisfied (use --upgrade to upgrade): pycrypto in /usr/local/lib/python2.7/site-packages` -- my script still can't find PyCrypto – chovy Dec 02 '15 at 07:17
  • Sounds like `/usr/local/lib/python2.7/site-packages` is not in your `PYTHONPATH` – thinkski Dec 03 '15 at 00:50
  • could be....`PYTHONPATH` is null. I already solved it by doing `easy_install` for pyCrypto – chovy Dec 03 '15 at 05:20
6

This works on Mojave and is better IMO than the other presented options: brew install gmp CFLAGS=-I/usr/local/include \ LDFLAGS=-L/usr/local/Cellar/gmp/6.1.2_2/lib \ pip install pycrypto

manimaul
  • 302
  • 3
  • 5
3

on El Capitan I just did this ...

sudo easy_install livestreamer
sudo easy_install PyCrypto

et voila... I can now save streams to my HDD.

GCU
  • 39
  • 1
2

I noticed recently that I needed brew to install gmp to get pip install pycrypto working again after upgrading OSX 10.9 and Xcode 5. But then the gmp build started failing on illegal text-relocation. It seems a known issue 12946 causes the compiler to fail compiling position independent code:

cc -bundle -undefined dynamic_lookup -Wl,-F. -Wno-error=unused-command-line-argument-hard-error-in-future -Wno-error=unused-command-line-argument-hard-error-in-future build/temp.macosx-10.9-intel-2.7/src/_fastmath.o -lgmp -o build/lib.macosx-10.9-intel-2.7/Crypto/PublicKey/_fastmath.so

ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: command 'cc' failed with exit status 1

Similar to the answer provided by radiofrequency I symlinked the shared library of gmp into the system's /usr/lib directory as a workaround:

sudo ln -s /usr/local/Cellar/gmp/5.1.3/lib/libgmp.dylib /usr/lib/libgmp.dylib

The gmp developer should add --with-pic.

Side point: the number of warnings building pycrypto does not provide comfort.

Community
  • 1
  • 1
bbaassssiiee
  • 4,879
  • 1
  • 34
  • 46
  • This worked for me. Obviously the version of gmp needs to be changed depending on the one installed on the machine. In my case I substituted 5.1.3 with 6.0.0a. Thanks. – foebu Dec 28 '14 at 14:24
1

For those of you also looking to install pycrypto as well as the cryptography package, this is the command that ended up working for me:

env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography

Nick Woodhams
  • 10,553
  • 10
  • 47
  • 51
1

For installation of PyCrypto use MacPorts and following command. I tested it on the newest version of Mac OS X - Yosemite:

Python Version 2.7:

sudo port install py27-crypto

Python Version 3.4:

sudo port install py34-crypto
AJF
  • 11,407
  • 2
  • 34
  • 59
Safronus
  • 19
  • 2
1

This is the only thing that worked for me on Mac/El Capitan:

sudo easy_install -U livestreamer

chovy
  • 59,357
  • 43
  • 187
  • 234
1

To install pycrypto run the following command

$ CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/Cellar/gmp/6.1.2_2/lib pip install pycrypto
Shivam Kohli
  • 319
  • 3
  • 4
0

Install homebrew (single line for installation at bottom of page), then try:

$ sudo pip install pycrypto
einnocent
  • 3,158
  • 3
  • 28
  • 37
0

If I'm not mistaken, pip and homebrew are both package managers, but homebrew is built on ruby and pip is built on python.

$ sudo pip install pycrypto

This command you referred to needs pip installed, not homebrew.

This way to get pip

  • If you do not have pip installed already, then you can install it first with `sudo python -m ensurepip` – FyKnight Jul 13 '17 at 06:09
0

I'm a new comer to python; I experienced this problem also; and it vexed me. None of the solutions posted worked for me, so I archived libgmp.a and libgmp.la temporarily, and pip then installed Crypto without error. Is this an acceptable approach? I have no understanding as to why this worked...

Mullefa
  • 1,107
  • 1
  • 14
  • 23