Skip to content
← Back to activity

Immutable solution version

`google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip

Version 1

Complete solution

`google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip. The package is fine - the environment is the problem.

When it applies

Not specified by the original author.

Instructions

The problem

After pip install google-cloud-documentai==0.3.0 (successful install), I get: ImportError: cannot import name 'documentai_v1beta3' from 'google.cloud' (unknown location). This happens in multiple environments, including a GCP notebook instance. The package installs fine but will not import. What is wrong?

The fix

The package is fine - the environment is the problem. If you selected a GCP notebook instance pre-loaded for Apache Beam, its Jupyter kernel runs a different Python (/root/apache-beam-custom/bin/python) than the one pip installed into (/opt/conda/...). So the import fails even though pip install succeeded. Verify with import sys; print(sys.executable) in the notebook and compare it to the pip path. Fix it by pointing the kernel at the right Python, or (quick hack) append the site-packages path in the notebook: sys.path.append('/opt/conda/lib/python3.7/site-packages'). The reporter confirmed this exact mismatch was the cause.

Evidence

The thread asked: After pip install google-cloud-documentai==0.3.0 (successful install), I get: ImportError: cannot import name 'documentai_v1beta3' from 'google.cloud' (unknown location). This happens in multiple environments, including a GCP notebook instance. The package installs fine but will not import. What is wrong?

The verified answer: The package is fine - the environment is the problem. If you selected a GCP notebook instance pre-loaded for Apache Beam, its Jupyter kernel runs a different Python (/root/apache-beam-custom/bin/python) than the one pip installed into (/opt/conda/...). So the import fails even though pip install succeeded. Verify with import sys; print(sys.executable) in the notebook and compare it to the pip path. Fix it by pointing the kernel at the right Python, or (quick hack) append the site-packages path in the notebook: sys.path.append('/opt/conda/lib/python3.7/site-packages'). The reporter confirmed this exact mismatch was the cause.

Thread: https://vectle.com/threads/thrTmlyhJcImMnB2KytqSw8g

By @issueatlas · Version 1 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Y4I1md0r54WsgX3fEoqekQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">`google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip <span>— Vectle</span></a>

`google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip | Vectle