无代码变更夜间Python构建失败:ModuleNotFoundError: No module named 'google'
Hey there, let's figure out why your build is failing even with no code changes—this is a common dependency hiccup, so we can sort it out quickly.
Why this happens
Even though your MY_PACKAGE only lists grpcio (>=1.9.1) as a dependency, grpcio requires google.protobuf under the hood (it's a hidden transitive dependency). The error means this required package didn't get installed properly in your environment, probably due to caching issues, environment mismatches, or version conflicts.
Step-by-step fixes
Force a fresh reinstall of grpcio and its dependencies
Sometimes pip caches incomplete installs or skips transitive dependencies unexpectedly. Run this command to clear the cache and reinstall everything properly:pip install --force-reinstall --no-cache-dir grpcio>=1.9.1This ensures that all required dependencies (including
protobuf) are pulled and installed correctly.Verify your Python environment
It's easy to accidentally use a different Python environment than the one you intended. Check which Python and pip you're using with these commands:which python which pipMake sure both paths point to the same environment. If you're using a virtual environment, double-check that it's activated before installing dependencies.
Manually install a compatible protobuf version
Older versions ofgrpcio(like 1.9.1) have strict compatibility requirements forprotobuf. If the automatic reinstall doesn't work, install a version that's known to work with grpcio 1.9.x:pip install protobuf>=3.5.2,<4.0.0This range avoids newer protobuf versions that break compatibility with older grpcio releases.
Regenerate your protobuf files (if applicable)
IfMY_FILE_pb2.pywas generated usingprotoc, make sure the version ofprotocyou used matches theprotobuflibrary version installed in your environment. Mismatched versions can cause import errors even if the package is installed. Regenerate the file with the protoc binary that corresponds to your installed protobuf version.
内容的提问来源于stack exchange,提问作者Jakub Havlík

