Apple Silicon / Python 3.8 - symbol not found in flat namespace '_ffi_prep_closure'
Most likely a repeat of #506 (closed).
I've currently got arm64 homebrew in /opt/homebrew, and i386 homebrew in /usr/local for a few legacy tools. Python 3.8 is provided by pyenv, and is native arm64.
If I try and install cffi:
Enlightenment:~ tomkins$ mktmpenv --python=python3.8
created virtual environment CPython3.8.12.final.0-64 in 138ms
creator CPython3Posix(dest=/Users/tomkins/.virtualenvs/tmp-cd582616b317f4f, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/tomkins/Library/Application Support/virtualenv)
added seed packages: pip==21.3.1, setuptools==58.3.0, wheel==0.37.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/bin/get_env_details
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-cd582616b317f4f) Enlightenment:tmp-cd582616b317f4f tomkins$ pip install --no-binary cffi cffi
WARNING: --use-feature=2020-resolver no longer has any effect, since it is now the default dependency resolver in pip. This will become an error in pip 21.0.
Collecting cffi
Using cached cffi-1.15.0.tar.gz (484 kB)
Preparing metadata (setup.py) ... done
Collecting pycparser
Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Skipping wheel build for cffi, due to binaries being disabled for it.
Installing collected packages: pycparser, cffi
Running setup.py install for cffi ... done
Successfully installed cffi-1.15.0 pycparser-2.21
(tmp-cd582616b317f4f) Enlightenment:tmp-cd582616b317f4f tomkins$ python
Python 3.8.12 (default, Nov 27 2021, 19:06:16)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _cffi_backend as backend
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/tomkins/.virtualenvs/tmp-cd582616b317f4f/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
>>>
However, if I run mv /usr/local/bin/brew /usr/local/bin/brew_
beforehand:
Enlightenment:~ tomkins$ mv /usr/local/bin/brew /usr/local/bin/brew_
Enlightenment:~ tomkins$ mktmpenv --python=python3.8
created virtual environment CPython3.8.12.final.0-64 in 138ms
creator CPython3Posix(dest=/Users/tomkins/.virtualenvs/tmp-387fe469c77cb58, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/tomkins/Library/Application Support/virtualenv)
added seed packages: pip==21.3.1, setuptools==58.3.0, wheel==0.37.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-387fe469c77cb58/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-387fe469c77cb58/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-387fe469c77cb58/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-387fe469c77cb58/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/tomkins/.virtualenvs/tmp-387fe469c77cb58/bin/get_env_details
This is a temporary environment. It will be deleted when you run 'deactivate'.
(tmp-387fe469c77cb58) Enlightenment:tmp-387fe469c77cb58 tomkins$ pip install --no-binary cffi cffi
WARNING: --use-feature=2020-resolver no longer has any effect, since it is now the default dependency resolver in pip. This will become an error in pip 21.0.
Collecting cffi
Using cached cffi-1.15.0.tar.gz (484 kB)
Preparing metadata (setup.py) ... done
Collecting pycparser
Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Skipping wheel build for cffi, due to binaries being disabled for it.
Installing collected packages: pycparser, cffi
Running setup.py install for cffi ... done
Successfully installed cffi-1.15.0 pycparser-2.21
(tmp-387fe469c77cb58) Enlightenment:tmp-387fe469c77cb58 tomkins$ python
Python 3.8.12 (default, Nov 27 2021, 19:06:16)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _cffi_backend as backend
>>>
Which is probably due to: https://foss.heptapod.net/pypy/cffi/-/blob/167cc9ea0ba43e5609e08c0e8d7085a454391f7a/setup.py#L108
This doesn't impact Python 3.9 or 3.10 - as wheels are available for those, so the issue is entirely bypassed.
As far as I'm aware, Homebrew uses system libffi for Python formulae, and pyenv uses system libffi. Also, given the warning/instructions from Homebrew libffi:
Enlightenment:~ tomkins$ brew info libffi
libffi: stable 3.4.2 (bottled), HEAD [keg-only]
Portable Foreign Function Interface library
https://sourceware.org/libffi/
/opt/homebrew/Cellar/libffi/3.4.2 (17 files, 673.3KB)
Poured from bottle on 2021-11-27 at 19:12:59
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libffi.rb
License: MIT
==> Options
--HEAD
Install HEAD version
==> Caveats
libffi is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
For compilers to find libffi you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"
For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig"
==> Analytics
install: 397,975 (30 days), 1,070,102 (90 days), 3,714,130 (365 days)
install-on-request: 12,777 (30 days), 36,447 (90 days), 146,899 (365 days)
build-error: 8 (30 days)
Should the check for Homebrew be removed? If a user wants Homebrew libffi - the instructions for environment variables are listed above.