-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Python - Mac M1 - ImportError: cannot import name '_message' from 'google.protobuf.pyext' #8820
Copy link
Copy link
Closed
Labels
Description
What version of protobuf and what language are you using?
Version: 3.17.3
Language: Python
What operating system (Linux, Windows, ...) and version?
Mac0S Big Sur 11.4, M1 version
What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.9.5
gcc:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
What did you do?
➜ python --version
Python 3.9.5
➜ python -m venv venv
➜ source venv/bin/activate
(venv) ➜ pip install -U pip protobuf
Requirement already satisfied: pip in ./venv/lib/python3.9/site-packages (21.1.1)
Collecting pip
Using cached pip-21.1.3-py3-none-any.whl (1.5 MB)
Collecting protobuf
Using cached protobuf-3.17.3-py2.py3-none-any.whl (173 kB)
Collecting six>=1.9
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, protobuf, pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
Successfully installed pip-21.1.3 protobuf-3.17.3 six-1.16.0
(venv) ➜ python -c "from google.protobuf.pyext import _message"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/Users/home/Programming/python/protobuf/venv/lib/python3.9/site-packages/google/protobuf/pyext/__init__.py)
What did you expect to see
A successful import.
What did you see instead?
ImportError: cannot import name '_message' from 'google.protobuf.pyext'
Anything else we should know about your project / environment
No
Other things I've tried
I have tried running the same snippet inside native and emulated docker containers. I could successfully install protobuf in the emulated container.
# The relevant protobuf file:
FROM python:3.9.5
RUN pip install -U pip protobuf
CMD ["python", "-c", "from google.protobuf.pyext import _message"]➜ docker build -t protobuf-arm .
[+] Building 2.8s (7/7) FINISHED
...
➜ docker run --rm -it protobuf-arm
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/usr/local/lib/python3.9/site-packages/google/protobuf/pyext/__init__.py)
➜ export DOCKER_DEFAULT_PLATFORM=linux/amd64 && docker build -t protobuf-amd .
[+] Building 2.0s (6/6) FINISHED
...
➜ protobuf docker run --rm -it protobuf-amd
➜
EDIT: This issue persists for protobuf version 3.18.0.
Reactions are currently unavailable