question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feast init: ImportError: cannot import name '_message' from 'google.protobuf.pyext'

See original GitHub issue

After running the command feast init feature-repo-name, I received an error

ImportError: cannot import name '_message' from 'google.protobuf.pyext' (/opt/homebrew/Caskroom/miniforge/base/envs/intel_py39/lib/python3.9/site-packages/google/protobuf/pyext/__init__.py)

Here is what I have tried but none was working as I received the exact same error

  1. Reinstall protobuf to the latest version using
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
pip3 install --upgrade --force-reinstall protobuf
  1. Switch to a Mac with an Intel chip and run everything all over again

Specifications

  • Version: feast 0.14.1
  • Platform:
    • macOS Big Sur (version 11.6) (Apple M1 chip)
    • python 3.9.7
  • Dependencies:
    • protobuf 3.19.1
    • google-api-core 2.2.1
    • googleapis-common-protos 1.52.0
    • google-auth 2.3.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

4reactions
TeoZosacommented, Nov 10, 2021

I also ran into the same issue but was able to get it working. My solution (originally posted in https://github.com/protocolbuffers/protobuf/issues/8820#issuecomment-961552604):

I had the same problem and discovered it was because required shared libraries are missing from the -py2.py3-none-any.whl pure python wheel that gets pulled in automatically.

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}')" --force-reinstall --no-deps --install-option="--cpp_implementation"

Hope this helps!

Edit (2021/11/09):

  • Note that this installs the version of the protobuf Python library that matches the version of the pre-compiled protoc binary that was installed via brew (brew install protobuf).
  • If you need a newer version than what brew provides, you’re going to have to build protoc from source. This would look something like:
# 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" 
1reaction
duy-effectivcommented, Nov 5, 2021

I also ran into the same issue but was able to get it working. My solution (originally posted in protocolbuffers/protobuf#8820 (comment)):

I had the same problem and discovered it was because required shared libraries are missing from the -py2.py3-none-any.whl pure python wheel that gets pulled in automatically. 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}')" --force-reinstall --no-deps --install-option="--cpp_implementation"

Hope this helps!

Thank you so much @TeoZosa . It works for me now. Finally!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot import name '_message' from 'google.protobuf.pyext' (c ...
What does the above command do? Why do I get this error message? C:\Windows\system32>python --version Python 3.7.1 C:\Windows ...
Read more >
tensorflow - Bountysource
ImportError : cannot import name '_message' from 'google.protobuf.pyext' (/usr/lib/python3.7/site-packages/google/protobuf/pyext/__init__.py)
Read more >
Python CPP backend bug: cannot import name ...
File "build\bdist.win-amd64\egg\google\protobuf\internal\cpp_message.py", line 39, in <module> ImportError: cannot import name _net_proto2___python.
Read more >
google.protobuf.descriptor — Apache Beam documentation
The name of the class is required in case the options message is None and has to ... _options from google.protobuf import descriptor_pb2...
Read more >
[protobuf] Python CPP backend bug: cannot import name ...
Hi, I get the aforementioned error message when trying to use the cpp backend for python with the new version 2.6.0:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found