black: Does not work on Apple Silicon

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Install with pip

Expected behavior

Just work

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: macOS 11.2.3 (20D91)
  • Python: 3.9.x

Does this bug also happen on master? To answer this, you have two options:

Ran on my machine resulted in:

pip install -e .:

Obtaining file:///Users/marvin/Downloads/black-test
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: pathspec<1,>=0.6 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (0.8.1)
Requirement already satisfied: regex>=2020.1.8 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (2021.3.17)
Requirement already satisfied: appdirs in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (1.4.4)
Requirement already satisfied: mypy-extensions>=0.4.3 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (0.4.3)
Requirement already satisfied: toml>=0.10.1 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (0.10.2)
Requirement already satisfied: click>=7.1.2 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (7.1.2)
Requirement already satisfied: typed-ast>=1.4.2 in /Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages (from black==20.8b2.dev118+gc702588) (1.4.2)
Installing collected packages: black
  Attempting uninstall: black
    Found existing installation: black 20.8b2.dev118+gc702588
    Uninstalling black-20.8b2.dev118+gc702588:
      Successfully uninstalled black-20.8b2.dev118+gc702588
  Running setup.py develop for black
Successfully installed black

python -m unittest:

EEE....[2021-03-31 14:23:30,423] DEBUG: Using selector: KqueueSelector (selector_events.py:59)
.[2021-03-31 14:23:30,424] DEBUG: Using selector: KqueueSelector (selector_events.py:59)
E[2021-03-31 14:23:30,790] DEBUG: Using selector: KqueueSelector (selector_events.py:59)
.[2021-03-31 14:23:30,790] DEBUG: Using selector: KqueueSelector (selector_events.py:59)
[2021-03-31 14:23:30,791] INFO: 17 projects to run Black over (lib.py:316)
[2021-03-31 14:23:30,791] DEBUG: Using 2 parallel workers to run Black (lib.py:321)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on aioexabgp (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on attrs (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on bandersnatch (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on channels (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on django (lib.py:252)
[2021-03-31 14:23:30,791] INFO: Skipping django as it's disabled via config (lib.py:259)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on flake8-bugbear (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on hypothesis (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on pandas (lib.py:252)
[2021-03-31 14:23:30,791] INFO: Skipping pandas as it's disabled via config (lib.py:259)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on pillow (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on poetry (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on ptr (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on pyramid (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on pytest (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on sqlalchemy (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on tox (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on virtualenv (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: worker 0 working on warehouse (lib.py:252)
[2021-03-31 14:23:30,791] DEBUG: project_runner 0 exiting (lib.py:250)
[2021-03-31 14:23:30,791] DEBUG: project_runner 1 exiting (lib.py:250)
[2021-03-31 14:23:30,791] INFO: Analyzing results (lib.py:332)
.
======================================================================
ERROR: tests.test_black (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_black
Traceback (most recent call last):
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/Users/marvin/Downloads/black-test/tests/test_black.py", line 13, in <module>
    import regex as re
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
	/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
	/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture


======================================================================
ERROR: tests.test_blackd (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_blackd
Traceback (most recent call last):
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/Users/marvin/Downloads/black-test/tests/test_blackd.py", line 7, in <module>
    from tests.util import read_data, DETERMINISTIC_HEADER, skip_if_exception
  File "/Users/marvin/Downloads/black-test/tests/util.py", line 6, in <module>
    import black
  File "/Users/marvin/Downloads/black-test/src/black/__init__.py", line 17, in <module>
    import regex as re
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
	/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
	/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture


======================================================================
ERROR: tests.test_format (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_format
Traceback (most recent call last):
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/Users/marvin/Downloads/black-test/tests/test_format.py", line 3, in <module>
    import black
  File "/Users/marvin/Downloads/black-test/src/black/__init__.py", line 17, in <module>
    import regex as re
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
	/Users/marvin/.pyenv/versions/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
	/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture


======================================================================
ERROR: test_gen_check_output (tests.test_primer.PrimerLibTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/Users/marvin/Downloads/black-test/tests/test_primer.py", line 143, in test_gen_check_output
    stdout, stderr = loop.run_until_complete(
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/marvin/Downloads/black-test/src/black_primer/lib.py", line 68, in _gen_check_output
    raise CalledProcessError(
subprocess.CalledProcessError: Command 'black --help' returned non-zero exit status 1.

----------------------------------------------------------------------
Ran 11 tests in 0.371s

FAILED (errors=4)

black --version:

Traceback (most recent call last):
  File "/Users/marvin/.pyenv/versions/black-test/bin/black", line 33, in <module>
    sys.exit(load_entry_point('black', 'console_scripts', 'black')())
  File "/Users/marvin/.pyenv/versions/black-test/bin/black", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/Users/marvin/.pyenv/versions/3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/marvin/Downloads/black-test/src/black/__init__.py", line 17, in <module>
    import regex as re
  File "/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
    import regex._regex_core as _regex_core
  File "/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ImportError: dlopen(/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found.  Did find:
	/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
	/Users/marvin/.pyenv/versions/3.9.2/envs/black-test/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17

Most upvoted comments

I don’t think the issue has been fixed in the standard library re module. Maybe we could avoid using regexes altogether though, so we don’t have to rely on any regex library’s unicode support or lack thereof.

So lets read the error you have there. This is not black at all but a dependency, regex. It’s a C extension, so has to be compiled for each CPU architecture and platform. You somehow have a non arm64 version:

/Users/smirnoffs/dev/shortme/.venv/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture

So please get an arm64 regex into your environment. Maybe try pip uninstall regex ; pip install regex

Did you port this venv from another Mac? Download an already made venv or old version of regex that does not have an arm64 wheel?

So on my brand new M1 Apple pip install black just all worked.

Here is the output: https://pastebin.com/BFacjTMz

I’m using Python 3.9.2 via brew

Commands to install (with no error:

mkdir -p ~/venvs/b
python3 -m venv --upgrade-deps ~/venvs/b # --update-deps ensure I have latest `pip` - This is >= 3.9
~/venvs/b/bin/pip install -U black 2>&1 | tee /tmp/black_install

I also had pre installed the Xcode developer tools. To install these it’s:

sudo xcode-select --install

Please reopen if any more issues exist.

I’m getting a M1 in the next few days. I’ll see what I can do, but if you install regex module from source I feel it will work. It’s our main compiled dependency.