ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

PythonPipCryptographyPython Cryptography

Python Problem Overview


I get an error when pip builds wheels for the cryptography package.

Error:

Error

LINK : fatal error LNK1181: cannot open input file 'libssl.lib'
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x86\\link.exe' failed with exit status 1181
  ----------------------------------------
  ERROR: Failed building wheel for cryptography
  Running setup.py clean for cryptography
Failed to build cryptography
ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

I have already installed OpenSSL and set the environment variables as suggested in this post yet the problem persists. My setup details:

  • System - Windows 10
  • Python - 3.8
  • Pip - 19.3.1

Python Solutions


Solution 1 - Python

Setting cryptography to version 2.8 in requirements.txt fixed the issue.

Solution 2 - Python

TLDR;

Try using cryptography==3.1.1

Details:

This happened on Python 3.9.0 on Windows 10 PC. I had the following in requirements.txt

cryptography==2.8

I removed the version and kept only cryptography in requirements.txt file like below

cryptography

Saved the requirements.txt and then I ran

pip install -r requirements.txt

It installed successfully. Then I freeze the requirements.txt by running the following command

pip freeze > requirements.txt

Then the requirements.txt got updated with cryptography==3.1.1

Solution 3 - Python

In my case (windows 10 + conda) updating pip fixed the problem:

python -m pip install --upgrade pip

Solution 4 - Python

Had also this issue. If you're using alpine, make sure that all dependencies for cryptography are installed. In my case the cargo package was missing and causing the issue.

sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

https://cryptography.io/en/latest/installation.html#building-cryptography-on-linux

Solution 5 - Python

Ran into this issue, and the solution is actually in the message when pip attempts to install openssl before cryptography:

  generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
  running build_rust
  
      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================

Simply running the pip update command appeared to work for me:

pip install -U pip

Which updated pip from version 18.0 to version 21.0.1

Solution 6 - Python

You can use the lastest version with

python3 -m pip install --no-use-pep517 cryptography

worked for me with ubuntu:18.04 on arm32v7 (instead as suggested by the error message install the full rust compiler and build-essentials, or upgrading pip (what had no effect on ubuntu:18.04 on my armbian))

Solution 7 - Python

pip install --upgrade pip

Try to upgrade pip of your environment working fine for me.

Solution 8 - Python

I got this error trying to install Scrapy with Python 3.8.1 on Windows 10, but its solved installing the last version of pip (19.3.1 in my case) and all works using pip in this way:

python -m pip install scrapy --user

Solution 9 - Python

I have faced same issue and tried to install openssl with mentioned step but still was not able to proceed for windows 10. Later I upgraded pip to latest version and tried again and it worked without any issue.

I would recommend to upgrade pip to latest version and give a try before proceeding for installing openssl

Solution 10 - Python

I had the same issue. pip3 version was 19.* after upgrade it works

sudo -H pip3 install --upgrade pip

Solution 11 - Python

You can try to install cryptography==3.1.1 package instead of cryptography 35 version.

pip install cryptography==3.1.1

If still you are facing challenges in cryptography package integration.

You can resolve that by the following steps.

python -m pip install --upgrade pip

sudo pip install -U pip setuptools

Solution 12 - Python

I faced this issue on macOS Monterey (version 12.2.1) Apple M1 Pro. I followed Cryptography installation documentation and it helped me resolve the issue.

brew install [email protected] rust

env CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS=1 LDFLAGS="$(brew --prefix [email protected])/lib/libssl.a $(brew --prefix [email protected])/lib/libcrypto.a" CFLAGS="-I$(brew --prefix [email protected])/include" pip3 install cryptography

Solution 13 - Python

I had this problem and i just installed rust and problem fixed for me You can install end version of cryptography after installing rust programming languege(dont try pip install rust, its not python package) https://www.rust-lang.org/tools/install

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChirag BhansaliView Question on Stackoverflow
Solution 1 - PythonAbhiView Answer on Stackoverflow
Solution 2 - PythonnavuleView Answer on Stackoverflow
Solution 3 - PythonJoséView Answer on Stackoverflow
Solution 4 - PythonlineconnectView Answer on Stackoverflow
Solution 5 - PythonAneuwayView Answer on Stackoverflow
Solution 6 - PythonFoxRomeoView Answer on Stackoverflow
Solution 7 - PythonAmit DagarView Answer on Stackoverflow
Solution 8 - PythonCamilo CaquimboView Answer on Stackoverflow
Solution 9 - PythonIdris MerchantView Answer on Stackoverflow
Solution 10 - Pythoninaxion-devView Answer on Stackoverflow
Solution 11 - PythonCodemakerView Answer on Stackoverflow
Solution 12 - PythonTushar NitaveView Answer on Stackoverflow
Solution 13 - PythonMasoud A.View Answer on Stackoverflow