17

Is there a package for Alpine which allows me to install PyCrypto for Python 3?

After encountering problems with pip3 install pycrypto, I stumbled upon this post which explains how to install numpy in Alpine using apk add py-numpy@testing. PyCrypto can also be installed for Python2.7 using apk add py-crypto. However, I cannot seem to figure out how to call pycrypto for Python3 or even if this package exists.

As an alternative solution, I tried to install the C compiler gcc using apk add gcc so that the setup tools in pip3 install pycrypto can compile. But, when I run that command with gcc already, it throws a fatal error:

...
running build_ext
running build_configure
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/tmp/pip-build-2TivSm/pycrypto':
configure: error: C compiler cannot create executables
...

Is there no way to compile Python3 modules inside Alpine?

R J
  • 4,473
  • 2
  • 22
  • 29

3 Answers3

32

This worked for me:

apk add gcc g++ make libffi-dev openssl-dev

Then do your pip install.

zbyte
  • 3,705
  • 1
  • 17
  • 13
  • 5
    Great! That was the trick. Thanks. However, I also needed to install python3-dev as well using this: `apk add python3-dev build-base --update-cache` – R J Mar 01 '16 at 02:56
  • Your command worked perfectly for compiling `pycryptodome` in `alpine` when I needed to use it for a Docker project. +1. – Carlos Jul 17 '19 at 06:01
4

configure: error: C compiler cannot create executables

In alpine Install their SDK.

For any compiling stuff in Alpine, make sure you have these packages.

alpine-sdk autoconf automake libtool

Install it apk add --no-cache alpine-sdk autoconf automake libtool

Leo Prince
  • 2,019
  • 26
  • 29
-3

PyCrypto seems to have problems with python 3, i had a lot of struggle with that. If you are using Windows, this is the solution that worked for me:

  • Install Visual Studio 2015 with Visual C++ (VS Version 2015 only works if you are using python 3.5+. If you are using 3.4, i think the correct version was VS2010. For earlier versions i am not really sure which version to choose but you can find information about that on the internet)
  • Download the pycrypto source. Currently the stable release is pycrypto-2.6.1. Use this one and not the experimental version below.
  • Extract the archive
  • Edit the file lib/Crypto/Random/OSRNG/nt.py and replace import winrandom with from Crypto.Random.OSRNG import winrandom.
  • Run the following from cmd python setup.py build -c msvc python setup.py install python setup.py test
  • If the test gets you some errors, you might get away with it anyways.

Instructions taken from my github project (dev branch).

Florian Lüdiger
  • 168
  • 3
  • 12