8

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?

2
  • Possible duplicate of stackoverflow.com/questions/65069019/… Commented Nov 30, 2020 at 12:10
  • Don't use the system Python. Install Anaconda or Python through brew. Commented Nov 30, 2020 at 12:25

3 Answers 3

21

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

  export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

You can view the command by yourself entering

brew info openssl
Sign up to request clarification or add additional context in comments.

3 Comments

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!
If you're installing an older version of cryptography (like 2.9.x) you have to link with [email protected] instead of openssl@3.
is this with the assumption that "brew install openssl" was run previously? It's not installed on my system att.
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.

2 Comments

Thanks, you saved my day :) I'm just curious, how did you come to this solution? Which documentation indicated to use these flags?
Not the author, but brew info openssl will print out the env exports to run to get the flags :)
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.