2

I'm trying to install the cryptography python library using pip (so I can use paramiko), but I'm getting a gcc error.

Some background: this is on a CentOS 5.11 VM that I was given with Python 2.4.3 installed. I installed Python 2.7.12 alongside it, and had to struggle a little bit to get all the dependencies for cryptography installed.

When I run the command

sudo pip2.7 install cryptography

I first get an SNIMissingWarning error (which I think is tangential, but I'll give details at the end of the question, in case it's not). Then I get several hundred lines of install logs, finally ending with:

build/temp.linux-i686-2.7/_openssl.c:72077: error: storage class specified for parameter ‘_cffi_type_context’

build/temp.linux-i686-2.7/_openssl.c:72077: error: parameter ‘_cffi_type_context’ is initialized

build/temp.linux-i686-2.7/_openssl.c:72120: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

build/temp.linux-i686-2.7/_openssl.c:72122: error: old-style parameter declarations in prototyped function definition

build/temp.linux-i686-2.7/_openssl.c:591: error: parameter name omitted

build/temp.linux-i686-2.7/_openssl.c:72122: error: expected ‘{’ at end of input

error: command 'gcc' failed with exit status 1


Command "/usr/local/bin/python2.7 -u -c "import setuptools, tokenize;file='/tmp/pip-build-RGpvd5/cryptography/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-kwpB5q-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-RGpvd5/cryptography/

Since it's a gcc error, I'm not sure what to do. I looked for information about it, but I don't know much about C, so the answers didn't mean much to me. I couldn't find anything relating to installing cryptography for python discussing this specific error.

Any ideas what may be happening?


In more detail, the SNIMissingWarning message I get is:

/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/vendor/requests/packages/urllib3/util/ssl.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.

SNIMissingWarning

Using cached cryptography-1.6.tar.gz

The readthedocs.io link has this to say about the error: "This happens on Python 2 versions older than 2.7.9. These older versions lack SNI support." Since I am using 2.7.12, hopefully that's not a problem. It further suggests installing urllib3 with the secure option, which I tried, using

pip2.7 install urllib3[secure]

This automatically attempted to install cryptography, and that failed with a gcc error, the same way as before.

bso
  • 23
  • 1
  • 5

2 Answers2

1

I remember having difficulty with this as well. From what I remember, the command that worked for me was: sudo python -m pip install cryptography

If Python 2.7 isn't default on your system, you may need to use: sudo python2.7 -m pip install cryptography

Edit: Thought I'd also add this. Try reinstalling gcc. Since you're on CentOS: $ sudo yum reinstall gcc

Andrew Lamarra
  • 507
  • 2
  • 10
  • Thanks for the suggestion. I tried `sudo python2.7 -m pip install cryptography` and got the same error as before, unfortunately. – bso Nov 28 '16 at 23:41
  • Try reinstalling gcc. Since you're on CentOS: `$ sudo yum reinstall gcc` – Andrew Lamarra Nov 28 '16 at 23:58
  • I reinstalled gcc using the command you gave, but still got the same error. – bso Nov 29 '16 at 16:37
  • Maybe try reinstalling OpenSSL: `$ sudo yum reinstall openssl`. Also, check for some sort of gcc alias on your system. In the terminal, just type `alias` to output a list of all the aliases. See if any start with `gcc`. – Andrew Lamarra Nov 29 '16 at 20:07
  • I tried reinstalling openssl too, and still get the same error. There's no alias for gcc. I also tried reinstalling any other dependencies I could find, but it still errors out. Based on the error, this really seems like bug in the code, except that it's hard to believe a widely released package would have a problem like this - and if it did, I'd expect some discussion about it. There must be something somewhere wrong with this Centos installation, so I guess I'm going to have ask a sysadmin for a different OS. – bso Nov 30 '16 at 20:24
  • 3
    I probably should have checked this earlier, but make sure you have the required dependencies (https://cryptography.io/en/latest/installation/). `$ sudo yum install gcc libffi-devel python-devel openssl-devel` – Andrew Lamarra Nov 30 '16 at 20:53
  • They're there. I checked that before I posted. It took some effort to find the right repo for libffi-devel. It wasn't available in the repos that came on the VM. At this point I'm seeing that as a further indication that something is wrong with this box - like they purposefully use a stripped down image. – bso Nov 30 '16 at 21:45
  • Well, I did the pip install to get cryptography on my raspberry pi and got a bunch of errors like you did. After that I checked for the required packages and realized that some needed to be installed. After installing those, I tried running the `pip install cryptography` command again & it said all requirements were met. So I fired up python, tried doing an import from the module & it worked. Maybe see if it's working on your system already. Launch the python interpreter and try `>>> from cryptography.fernet import Fernet` – Andrew Lamarra Nov 30 '16 at 22:34
  • It's definitely not there. Thanks for trying, but I think I'm going to have to throw in the towel on centos 5, since it's not supported according to current cryptography documentation, and ask for a newer OS. Or try to make this with Docker, if I can't get a new VM. – bso Dec 02 '16 at 15:36
  • 4
    The resolution: our sysadmins gave me a new VM with CentOS 7.2, and I was able to get cryptography and paramiko installed. Even then, it failed until I ran `sudo yum install gcc libffi-devel python-devel openssl-devel`. So this discussion did still end up being useful. – bso Dec 05 '16 at 17:05
1

This has happened to me with Python 3.6 on several occasions. The fix I found to work on every occasion is:

sudo apt update
sudo apt install gcc libffi-dev libbz2-dev

Then, if you get a This package requires Rust >= x.x.x complaint you might need:

sudo apt install rustc
pip install rust

Then carry on with:

pip install cryptography

If this fails with ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly, use the following as mentioned in this answer. In my case, cryptography 3.4.7 failed with this error.

pip install cryptography==3.1.1
S3DEV
  • 8,768
  • 3
  • 31
  • 42