Cryptography: Native Compile Error on Windows: Cannot open include file: 'openssl/opensslv.h'

Created on 30 Jun 2016  Â·  11Comments  Â·  Source: pyca/cryptography

when trying to run python setup.py install on Windows (x64) the Compiler spits out an error while building ssl.

cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG "-I%PYTHON27%\include" "-I%PYTHON27%\PC" /Tcbuild\temp.win-amd64-2.7\Release\_openssl.c /Fobuild\temp.win-amd64-2.7\Release\build\temp.win-amd64-2.7\Release\_openssl.obj
_openssl.c
build\temp.win-amd64-2.7\Release\_openssl.c(429): fatal error C1083: Cannot open include file: 'openssl/opensslv.h': No such file or directory

I have opened the directtory in question and have verified that _openssl.c does in fact refer to openssl/opensslv.h on line 429. And no, there is no openssl directory next to the_openssl.c` file in my build folder.

Python: Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x64

Most helpful comment

In Windows 10 in PowerShell, if you need openssl, use Chocolatey package manager to install:

choco install openssl -pre -y

Then in a new1 PowerShell terminal, use

$env:LIB = (Resolve-Path -Path "$env:OPENSSL_CONF\..\..\lib"); $env:INCLUDE = (Resolve-Path -Path "$env:OPENSSL_CONF\..\..\include")
&python.exe -m pip install -U cryptography
  1. For some reason, the Chocolatey RefreshEnv.cmd tool doesn't actually pull the $env:OPENSSL_CONF environment variable for me, so I have to start a new terminal. ↩

All 11 comments

Never mind, RTFM!!!! Of course, I hadn't included OpenSSL in lib and include path! :/

You will definitely have to do that (as we documented) if you want to compile it yourself, but if you're on pip6+ you should get a statically linked wheel by default and not need to compile anything when you type pip install cryptography

@couven92 how do you include OpenSSL in INCLUDE and LIB paths? Am having problems in Windows 10.

You should not need to compile cryptography yourself unless you're doing something very unusual. On Windows just make sure you have an up-to-date pip and pip install cryptography will just work.

@reaperhulk I had an unusually messed up installation of cryptography (possibly by another package that I installed which depended on it and installed an old version or messed it up in some other way). I just reinstalled it by doing pip install cryptography and now it works properly.

I am using fresh virtual env with pip 19.0.3 and the same problem on my side.
The cause is Intellij PyCharm virtual env. While installing to main python env on the system everything works fine. While installing in virtual env made by PyCharm i need the libs.

@bukowa Your comment turned out to be the key to figuring out my problem. I was running Python 3.8 and have a project with a requirements file that was created under Python 3.7 and called for cryptography 2.6.1. 2.8 is the first version that is compiled for Python 3.8. When no pre-compiled version exists, pip will try to compile it for you (PEP 517 is the relevant standard). I restarted the venv with Python 3.7 and everything cooperated (I'll have to talk to the project maintainer about upgrading later).

That said, I spent many hours trying to figure out what the system required for OpenSSL without success. I tried installing a Windows binary from the list provided by https://wiki.openssl.org/index.php/Binaries and I also tried with the raw source code for OpenSSL 1.1.1d, setting the LIB and INCLUDE variables to point to the respective OpenSSL folders on each attempt. Doing it with the installed binary did nothing, doing it with the source cleared the first error and threw a new one. The install docs for Cryptography are unclear to someone who isn't familiar or comfortable with compiling software on Windows. (Compiler is MSVC v142, installed because cffi demanded it.)

This is how i compiled myself:

  1. Install https://slproweb.com/products/Win32OpenSSL.html (32bit)
  2. Before installing cryptography:
set LIB=C:\Program Files (x86)\OpenSSL-Win32\lib;%LIB%
set INCLUDE=C:\Program Files (x86)\OpenSSL-Win32\include;%INCLUDE%

That's the same place i got my binaries, except I got the 64-bit version. I just tried building 2.6.1 in a one-off venv following those steps (with corrected file paths of course) and still got the error.

It won't compile using 64bit version, try using 32bit

In Windows 10 in PowerShell, if you need openssl, use Chocolatey package manager to install:

choco install openssl -pre -y

Then in a new1 PowerShell terminal, use

$env:LIB = (Resolve-Path -Path "$env:OPENSSL_CONF\..\..\lib"); $env:INCLUDE = (Resolve-Path -Path "$env:OPENSSL_CONF\..\..\include")
&python.exe -m pip install -U cryptography
  1. For some reason, the Chocolatey RefreshEnv.cmd tool doesn't actually pull the $env:OPENSSL_CONF environment variable for me, so I have to start a new terminal. ↩
Was this page helpful?
0 / 5 - 0 ratings