New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python - Mac M1 - ImportError: cannot import name '_message' from 'google.protobuf.pyext' #8820
Comments
Some of my colleagues also recently received M1 macs, and I asked them to follow the same steps to install I have no idea what the difference in setups is exactly. |
I had the same problem and discovered it was because required shared libraries are missing from the I was able to solve it by building the protobuf wheel from source: brew install protobuf
export CFLAGS="-I$(brew --prefix protobuf)/include"
export LDFLAGS="-L$(brew --prefix protobuf)/lib"
# In my virtual environment:
pip install protobuf=="$(brew list --version protobuf | awk '{print $2}')" --install-option="--cpp_implementation"
# If the pure python protobuf wheel is already installed, run this instead:
# pip install protobuf=="$(brew list --version protobuf | awk '{print $2}')" --force-reinstall --no-deps --install-option="--cpp_implementation"
Hope this helps! Edit (2021/11/09):
# Download and unpack protobuf compiler source code
PROTOBUF_RELEASES_URL="https://github.com/protocolbuffers/protobuf/releases/download"
TARGET_PROTOBUF_VERSION=$(pip show protobuf | grep Version | sed -r 's/Version: (.*)/\1/') # get the version of the (broken) protobuf wheel currently installed
PROTOC_SRC_ARCHIVE="protobuf-cpp-${TARGET_PROTOBUF_VERSION}.tar.gz"
curl -sSL "${PROTOBUF_RELEASES_URL}/v${TARGET_PROTOBUF_VERSION}/${PROTOC_SRC_ARCHIVE}" | tar -C /tmp -xzf -
# Build protobuf compiler from source (this will take a while)
# see: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
PROTOC_SRC_PATH="/tmp/protobuf-${TARGET_PROTOBUF_VERSION}" && \
pushd "${PROTOC_SRC_PATH}" && \
./configure && \
make -j8 && \
make check && \
sudo make install && \
popd && \
rm -rf "${PROTOC_SRC_PATH}" # Clean src/build files # In your virtual environment:
INSTALL_PREFIX_PATH="/usr/local" && \
export CFLAGS="-I${INSTALL_PREFIX_PATH}/include" && \
export LDFLAGS="-L${INSTALL_PREFIX_PATH}/lib" && \
pip install protobuf=="${TARGET_PROTOBUF_VERSION}" --force-reinstall --no-deps --install-option="--cpp_implementation" |
This solved my problem. Thanks! |
We are currently preparing a 4.21.0 release of protobuf which will release with M1-compatible The M1 support will not be in 4.21.0-rc1, but it should be in all subsequent releases. This is part of a major rework of the C extension which should also deliver some performance improvements. I expect these performance improvements to be especially noticeable on Mac: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates |
A universal binary has been published for 4.21.0! Feel free to open another bug if this issue still exists in the new version. |
Import error on M2 Mac. ModuleNotFoundError: |
Underscore-prefixed names like More info here: #15643 (comment) |
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:
What did you do?
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.
EDIT: This issue persists for protobuf version
3.18.0
.The text was updated successfully, but these errors were encountered: