Wednesday, February 8, 2012

PyCrypto on OS X Lion

Why yes, I HAVE been having fun* installing python packages again. I need to SSH from Python, so I installed paramiko. Importing that told me I needed to install PyCrypto. Installing PyCrypto, I got this error:


arete:scratch catherine$ easy_install PyCrypto
Searching for PyCrypto
Reading http://pypi.python.org/simple/PyCrypto/
Reading http://pycrypto.sourceforge.net
Reading http://www.amk.ca/python/code/crypto
Reading http://www.pycrypto.org/
Best match: pycrypto 2.5
Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.5.tar.gz
Processing pycrypto-2.5.tar.gz
Running pycrypto-2.5/setup.py -q bdist_egg --dist-dir /var/folders/vn/y9kznfvx0zv06kxlvn111pp40000gn/T/easy_install-8aXjiK/pycrypto-2.5/egg-dist-tmp-L9drMW
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
unable to execute gcc-4.2: No such file or directory
error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1

Whoops.

Here's the magic incantation to fix this:


arete:scratch catherine$ sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

And now our install goes juuuust fine.
arete:scratch catherine$ easy_install PyCrypto
Searching for PyCrypto
Reading http://pypi.python.org/simple/PyCrypto/
Reading http://pycrypto.sourceforge.net
Reading http://www.amk.ca/python/code/crypto
Reading http://www.pycrypto.org/
Best match: pycrypto 2.5
Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.5.tar.gz
Processing pycrypto-2.5.tar.gz
Running pycrypto-2.5/setup.py -q bdist_egg --dist-dir /var/folders/vn/y9kznfvx0zv06kxlvn111pp40000gn/T/easy_install-JYVoZl/pycrypto-2.5/egg-dist-tmp-Kq95pu
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
zip_safe flag not set; analyzing archive contents...
Adding pycrypto 2.5 to easy-install.pth file


Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrypto-2.5-py2.7-macosx-10.6-intel.egg
Processing dependencies for PyCrypto
Finished processing dependencies for PyCrypto



Now, back to the work I meant to be doing!

*It's not actually fun. It's really sort of obnoxious.

15 comments:

  1. It would have been great to have found this post three hours ago. Fun indeed...

    ReplyDelete
  2. Hi, I am having the similar problem as you and followed your instructions but still not successful. Could you please see below and let me know what is going wrong?

    Thanks very much in advance!

    bash-3.2# easy_install PyCrypto
    Searching for PyCrypto
    Reading http://pypi.python.org/simple/PyCrypto/
    Reading http://pycrypto.sourceforge.net
    Reading http://www.amk.ca/python/code/crypto
    Reading http://www.pycrypto.org/
    Download error: [Errno 65] No route to host -- Some packages may not be found!
    Best match: pycrypto 2.5
    Downloading http://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.5.tar.gz#md5=783e45d4a1a309e03ab378b00f97b291
    Processing pycrypto-2.5.tar.gz
    Running pycrypto-2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-fEpoF_/pycrypto-2.5/egg-dist-tmp-jGd8gb
    src/_fastmath.c: In function ‘longObjToMPZ’:
    src/_fastmath.c:79: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c:81: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘mpzToLongObj’:
    src/_fastmath.c:105: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘sieve_field’:
    src/_fastmath.c:1249: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘rabinMillerTest’:
    src/_fastmath.c:1308: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c:1368: warning: implicit conversion shortens 64-bit value into a 32-bit value
    ld: warning: ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)
    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
    collect2: ld returned 1 exit status
    lipo: can't open input file: /var/tmp//ccvk87vl.out (No such file or directory)
    error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1
    bash-3.2# easy_install -f PyCrypto
    Not found: PyCrypto
    error: No urls, filenames, or requirements specified (see --help)
    bash-3.2# easy_install PyCrypto -f
    Searching for PyCrypto
    Reading http://pypi.python.org/simple/PyCrypto/
    Reading http://pycrypto.sourceforge.net
    Reading http://www.amk.ca/python/code/crypto
    Reading http://www.pycrypto.org/
    Download error: [Errno 65] No route to host -- Some packages may not be found!
    Best match: pycrypto 2.5
    Downloading http://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.5.tar.gz#md5=783e45d4a1a309e03ab378b00f97b291
    Processing pycrypto-2.5.tar.gz
    Running pycrypto-2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-jJnbSt/pycrypto-2.5/egg-dist-tmp-BiQzCY
    src/_fastmath.c: In function ‘longObjToMPZ’:
    src/_fastmath.c:79: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c:81: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘mpzToLongObj’:
    src/_fastmath.c:105: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘sieve_field’:
    src/_fastmath.c:1249: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c: In function ‘rabinMillerTest’:
    src/_fastmath.c:1308: warning: implicit conversion shortens 64-bit value into a 32-bit value
    src/_fastmath.c:1368: warning: implicit conversion shortens 64-bit value into a 32-bit value
    ld: warning: ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)
    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
    collect2: ld returned 1 exit status
    lipo: can't open input file: /var/tmp//ccbfxyD5.out (No such file or directory)
    error: Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1

    ReplyDelete
  3. Nomi, you're using llvm-gcc and it appears you're trying to compile it for 64-bit but you have a 32-bit python. Try using a 32-bit compiler to match you python version.

    ReplyDelete
  4. Thanks very much!

    I have another problem, which is totally different to the previous one (I think).

    Traceback (most recent call last):
    File "../src/deploy.py", line 4, in
    import paramiko
    File "build/bdist.macosx-10.7-intel/egg/paramiko/__init__.py", line 69, in
    File "build/bdist.macosx-10.7-intel/egg/paramiko/transport.py", line 32, in
    File "build/bdist.macosx-10.7-intel/egg/paramiko/util.py", line 32, in
    File "build/bdist.macosx-10.7-intel/egg/paramiko/common.py", line 98, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Random/__init__.py", line 29, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Random/_UserFriendlyRNG.py", line 38, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Util/Counter.py", line 30, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Util/_counter.py", line 7, in
    File "build/bdist.macosx-10.7-intel/egg/Crypto/Util/_counter.py", line 3, in __bootstrap__
    ImportError: No module named pkg_resources

    Any idea what is going wrong?

    Thanks!

    ReplyDelete
  5. Nomi, that's a problem with your python. It could be a PATH issue, or it could be that you upgraded your python and not all the packages upgraded cleanly. Check your python PATH, and if that doesn't turn anything up (and if you have recently upgraded your Python installation, try reinstalling setup tools: sudo easy_install install setuptools --upgrade

    ReplyDelete
  6. Well, I upgraded to Lion recently and have had problems since. I updated Xcode, and MacPorts. I must say that I am not very good at all with the programming stuff and hence you can see the struggle...

    This is how I installed Python:

    sudo port install py27-opengl

    ReplyDelete
  7. You kind of got me there, Nomi. I'm not really a fan of MacPorts, and I'm pretty rusty on it. I'd say check your paths and try reinstalling anything python-related that predates your OS/XCode upgrade.

    ReplyDelete
  8. easy_install PyCrypto
    Searching for PyCrypto
    Reading http://pypi.python.org/simple/PyCrypto/
    Reading http://pycrypto.sourceforge.net
    Reading http://www.amk.ca/python/code/crypto
    Reading http://www.pycrypto.org/
    Best match: pycrypto 2.5
    Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.5.tar.gz
    Processing pycrypto-2.5.tar.gz
    Running pycrypto-2.5/setup.py -q bdist_egg --dist-dir /var/folders/0_/wjvldgcd3rl7vg0686r6985m0000gp/T/easy_install-qK13xW/pycrypto-2.5/egg-dist-tmp-mciiXP
    ld: warning: ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)
    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
    collect2: ld returned 1 exit status
    lipo: can't open input file: /var/folders/0_/wjvldgcd3rl7vg0686r6985m0000gp/T//ccMl5aEf.out (No such file or directory)
    error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1

    and I have this::
    ls -al | grep gcc
    lrwxr-xr-x 1 root wheel 7 May 8 18:36 cc -> gcc-4.2
    lrwxr-xr-x 1 root wheel 12 May 8 19:11 gcc -> llvm-gcc-4.2
    -rwxr-xr-x 1 root wheel 113024 May 16 2011 gcc-4.2
    lrwxr-xr-x 1 root wheel 12 May 8 17:14 gcc-4.3 -> /usr/bin/gcc
    lrwxr-xr-x 1 root wheel 28 May 8 18:24 gcov-4.2 -> ../llvm-gcc-4.2/bin/gcov-4.2
    -rwxr-xr-x 1 root wheel 562992 May 16 2011 i686-apple-darwin11-gcc-4.2.1
    lrwxr-xr-x 1 root admin 52 May 8 18:24 i686-apple-darwin11-llvm-g++-4.2 -> ../llvm-gcc-4.2/bin/i686-apple-darwin11-llvm-g++-4.2
    lrwxr-xr-x 1 root admin 52 May 8 18:24 i686-apple-darwin11-llvm-gcc-4.2 -> ../llvm-gcc-4.2/bin/i686-apple-darwin11-llvm-gcc-4.2
    lrwxr-xr-x 1 root admin 32 May 8 18:24 llvm-cpp-4.2 -> ../llvm-gcc-4.2/bin/llvm-cpp-4.2
    lrwxr-xr-x 1 root admin 32 May 8 18:24 llvm-g++ -> ../llvm-gcc-4.2/bin/llvm-g++-4.2
    lrwxr-xr-x 1 root admin 32 May 8 18:24 llvm-g++-4.2 -> ../llvm-gcc-4.2/bin/llvm-g++-4.2
    lrwxr-xr-x 1 root admin 32 May 8 18:24 llvm-gcc -> ../llvm-gcc-4.2/bin/llvm-gcc-4.2
    lrwxr-xr-x 1 root admin 32 May 8 18:24 llvm-gcc-4.2 -> ../llvm-gcc-4.2/bin/llvm-gcc-4.2

    Please advice
    Thanks

    ReplyDelete
  9. Shimul, the problem is in the error you posted, if you read it carefully.
    " ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)"

    That file is important. You've got some 32 bit stuff compiling with some 64-bit stuff. Figure out which you want and reconcile your python, gcc, and pycrypto versions.

    ReplyDelete
  10. I know what is the problem but not sure how it happend and what/how I can fix.
    Thanks

    ReplyDelete
  11. It's the same fix as before. Figure out if you want 32 or 64-bit (this is driven by the libraries you want to use and what they support). Then start with python and make sure they're all in alignment. Google will help you help yourself with how to see what architecture you're compiled for.

    ReplyDelete
  12. can you help me with something similar?

    trying to install paramiko-1.10.1 and I get this.

    Processing
    Running setup.py -q bdist_egg --dist-dir /Users/nehe_maya/Desktop/paramiko-1.10.1/egg-dist-tmp-zz0tn2
    zip_safe flag not set; analyzing archive contents...
    paramiko 1.10.1 is already the active version in easy-install.pth

    Installed /Library/Python/2.6/site-packages/paramiko-1.10.1-py2.6.egg
    Processing dependencies for paramiko==1.10.1
    Searching for pycrypto>=2.1,!=2.4
    Reading http://pypi.python.org/simple/pycrypto/
    Reading http://pycrypto.sourceforge.net
    Reading http://www.pycrypto.org/
    Reading http://www.amk.ca/python/code/crypto
    Best match: pycrypto 2.6
    Downloading http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz
    Processing pycrypto-2.6.tar.gz
    Running pycrypto-2.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-50JaDi/pycrypto-2.6/egg-dist-tmp-IhSyJS
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
    Installed assemblers are:
    /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
    /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
    src/MD2.c:147: fatal error: error writing to -: Broken pipe
    compilation terminated.
    lipo: can't open input file: /var/tmp//cc8NdOu6.out (No such file or directory)
    error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1

    ReplyDelete
  13. Anonymous in april:

    This is your problem:

    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed

    The problem you're having is that it's looking for PPC (Power PC) libraries, when you're running an intel-based mac. That probably happened because you have Xcode 4 or later, which doesn't include ppc libraries.

    I _think_ you can get around this by setting your architecture flags. Do this:
    export ARCHFLAGS="-arch i386 -arch x86_64"

    Then run the commands you ran above.

    ReplyDelete
  14. Hi, I have a similar problem then the person above. I know that I have 64-bit python and I want to do everything in 64-bit (Mac OS). But I can't figure out what "some 32-bit stuff" is and how to fix it. I also tried with ARCHFLAGS="-arch i386 -arch x86_64" and ARCHFLAGS="-arch x86_64" but without success. Is it possible that gmp lib is in 32 bit and that I have to recompile that?

    Thanks!


    $ easy_install PyCrypto
    Searching for PyCrypto
    Reading https://pypi.python.org/simple/PyCrypto/
    Reading http://pycrypto.sourceforge.net
    Reading http://www.pycrypto.org/
    Reading http://www.amk.ca/python/code/crypto
    Best match: pycrypto 2.6
    Downloading https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz#md5=88dad0a270d1fe83a39e0467a66a22bb
    Processing pycrypto-2.6.tar.gz
    Writing /var/folders/cc/_mskgpdd6f77hrg4rsp4zq1h0000gq/T/easy_install-12bmpg/pycrypto-2.6/setup.cfg
    Running pycrypto-2.6/setup.py -q bdist_egg --dist-dir /var/folders/cc/_mskgpdd6f77hrg4rsp4zq1h0000gq/T/easy_install-12bmpg/pycrypto-2.6/egg-dist-tmp-7khnl4
    ld: warning: ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)
    ld: illegal text reloc to ___gmp_binvert_limb_table from /usr/local/lib/libgmp.a(mp_minv_tab.o) in ___gmpn_divexact_1 for architecture x86_64
    collect2: ld returned 1 exit status
    lipo: can't open input file: /var/folders/cc/_mskgpdd6f77hrg4rsp4zq1h0000gq/T//ccyi0csv.out (No such file or directory)
    error: Setup script exited with error: command 'gcc-4.2' failed with exit status 1

    ReplyDelete
  15. greg - this is the key part of your error message:

    Running pycrypto-2.6/setup.py -q bdist_egg --dist-dir /var/folders/cc/_mskgpdd6f77hrg4rsp4zq1h0000gq/T/easy_install-12bmpg/pycrypto-2.6/egg-dist-tmp-7khnl4
    ld: warning: ignoring file /usr/local/lib/libgmp.a, file was built for archive which is not the architecture being linked (i386)

    It's running pycrypto-2.06 setup, so you're installing pycrypto. It's trying to build pycrypto using a 32-bit architecture, and it's trying to link to a 64-bit library (libgmp in this case). So pycryptop is the 32-bit stuff, and you need to build it as a 64-bit architecture.

    ReplyDelete