7

I'm using macOS Big Sur 11.0.1.

I'm setting up a virtual env

$python3 -m venv $my_workdir)/.virtualenv

but getting this error at building wheel package:

building '_openssl' extension
  creating build/temp.macosx-10.14.6-x86_64-3.8/build
  creating build/temp.macosx-10.14.6-x86_64-3.8/build/temp.macosx-10.14.6-x86_64-3.8
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -I/usr/local/opt/gettext/include -I/Users/engontang/devspace/energisme/terraform/tfwrapper-infra-pda/.wrapper/.virtualenv/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c build/temp.macosx-10.14.6-x86_64-3.8/_openssl.c -o build/temp.macosx-10.14.6-x86_64-3.8/build/temp.macosx-10.14.6-x86_64-3.8/_openssl.o -Wconversion -Wno-error=sign-conversion
  build/temp.macosx-10.14.6-x86_64-3.8/_openssl.c:575:10: fatal error: 'openssl/opensslv.h' file not found
  #include <openssl/opensslv.h>
           ^~~~~~~~~~~~~~~~~~~~
  1 error generated.
  error: command 'clang' failed with exit status 1 

----------------------------------------

ERROR: Failed building wheel for cryptography

Building wheel for pynacl (PEP 517) ... /

As wheel is prebuilt with pip I thought it could be a pip upgrade issue, so I checked my pip version :

$pip --version                                                                                                                                                                                                      
pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)

I don't understand why python 2.7 is still mentionned above while my default python version is :

$python -V                                                                                                                                                                                                          
Python 3.8.2

Trying however to upgragde pip results in this :

$pip install --upgrade pip --user                                                                                                                                                                                   
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting pip
  Using cached pip-20.2.4-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  WARNING: The scripts pip, pip2 and pip2.7 are installed in '/Users/engontang/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.2.4

Using pip3 command gives the same result. You can see the DEPRECATION: Python 2.7 message above, and also pip still showing up the same version rather than 20.2.4:

$pip --version                                                                                                                                                                                                       
pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)

And my virtualenv setup still lead to the same above error.

Can one here say why pip is still looking at python 2.7 site packages, and what could be the problemm with wheel package build?

Jean-Pierre Matsumoto
  • 1,917
  • 1
  • 18
  • 26
nixmind
  • 2,060
  • 6
  • 32
  • 54

3 Answers3

20

For devices using Apple Silicon you may try this (as default homebrew bin directory differs)

  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

You can view the command by yourself entering

brew info openssl
Sajjad Shahi
  • 572
  • 4
  • 14
  • I did the `brew info openssl` and copied ```export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib" export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"``` and it at least got me past the missing header error. Thanks! – Matt Molnar Nov 23 '21 at 18:11
  • 2
    If you're installing an older version of `cryptography` (like 2.9.x) you *have* to link with `openssl@1.1` instead of `openssl@3`. – villasv Dec 17 '21 at 14:58
  • is this with the assumption that "brew install openssl" was run previously? It's not installed on my system att. – majorgear Oct 04 '22 at 16:00
6

Setting compilation Flags helped solving the openssl for wheel issue:

export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

But still don't understand the above described pip behavior.

nixmind
  • 2,060
  • 6
  • 32
  • 54
  • 1
    Thanks, you saved my day :) I'm just curious, how did you come to this solution? Which documentation indicated to use these flags? – Yash Sodha Dec 07 '20 at 20:37
  • 3
    Not the author, but `brew info openssl` will print out the env exports to run to get the flags :) – Sami Farhat Apr 04 '21 at 08:42
0

I agree with Luca

  1. Install python using brew install python
  2. Check the location of the installed file ls -l /usr/local/bin/python
  3. ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python
  4. Check the version again python --version

And if you don't already have Homebrew installed on your mac, you can find the instructions here: https://docs.brew.sh/Installation

Data Monger
  • 106
  • 10