{"record":{"id":"45a266e9e7b84b86","repo":"apache/beam","slug":"apache-beam-installation-failed-in-virtualenv","errorCode":null,"errorMessage":"apache beam installation failed in virtualenv","messagePattern":"apache beam installation failed in virtualenv","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":487,"sourceCode":"\t\terr = exec.Command(venvPython, \"-m\", \"pip\", \"install\", \"--upgrade\", \"setuptools\").Run()\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrap(err, \"error upgrading setuptools\")\n\t\t}\n\t\terr = exec.Command(venvPython, \"-m\", \"pip\", \"install\", beamPackage, \"pyparsing==2.4.2\").Run()\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrap(err, fmt.Sprintf(\"error installing beam package: %v\", beamPackage))\n\t\t}\n\t\tif len(extraPackages) > 0 {\n\t\t\tcmd := []string{\"-m\", \"pip\", \"install\"}\n\t\t\tcmd = append(cmd, extraPackages...)\n\t\t\terr = exec.Command(venvPython, cmd...).Run()\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", errors.Wrap(err, \"error installing dependencies\")\n\t\t\t}\n\t\t}\n\t\terr = exec.Command(venvPython, \"-c\", \"import apache_beam\").Run()\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrap(err, \"apache beam installation failed in virtualenv\")\n\t\t}\n\t}\n\treturn venvPython, nil\n}\n","sourceCodeStart":469,"sourceCodeEnd":492,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L469-L492","documentation":"Raised in expansionx.SetUpPythonEnvironment as a final sanity check: running `import apache_beam` with the venv's python failed after installation. It means apache_beam is installed but not importable, so the expansion service would not start correctly.","triggerScenarios":"startPythonExpansionService -> SetUpPythonEnvironment when the post-install verification `venvPython -c \"import apache_beam\"` exits non-zero — broken wheels, missing native libraries, or incompatible protobuf/dependency versions in the venv.","commonSituations":"Import-time errors like missing libso for grpc/protobuf, or 'google.protobuf' descriptor conflicts from mismatched protobuf versions; installing on an unsupported platform where a source build silently produced a broken package.","solutions":["Run `<venv>/bin/python -c \"import apache_beam\"` manually to see the ImportError/traceback","Fix the specific native dependency it reports (e.g. system libs) or switch to a supported OS/Python combo","Recreate the venv from scratch after deleting it to clear a corrupted install","Pin compatible transitive deps (e.g. protobuf) matching the installed apache_beam version"],"exampleFix":"// before\n// ImportError: libcffi ... / protobuf conflict\n// after\nrm -rf venv && python3.10 -m venv venv && ./venv/bin/pip install apache_beam==2.60.0\n./venv/bin/python -c \"import apache_beam\"","handlingStrategy":"try-catch","validationCode":"if err := exec.Command(venvPython, \"-c\", \"import apache_beam\").Run(); err != nil {\n    return fmt.Errorf(\"apache_beam not importable in venv: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"python, err := expansionx.SetUpPythonEnvironment(ctx, py, pkg, extras)\nif err != nil && strings.Contains(err.Error(), \"import apache_beam\") || strings.Contains(err.Error(), \"installation failed in virtualenv\") {\n    return fmt.Errorf(\"run the import manually to see the traceback, fix native deps, and recreate the venv: %w\", err)\n}","preventionTips":["Smoke-test `python -c \"import apache_beam\"` in a scratch venv on the target platform","Install required native libraries (gcc, libffi, openssl dev) for source builds","Pin transitive deps (protobuf/grpcio) compatible with the apache_beam version"],"tags":["python","apache-beam","import-error","virtualenv"],"backgroundTag":"module-init-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}