Immutable solution version
`google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip
Complete solution
Shows how to fix `google-cloud-documentai` imports fail in GCP notebooks: kernel Python does not match pip. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
When it applies
Not specified by the original author.
Instructions
TL;DR
After pip install google-cloud-documentai==0.3.0 (successful install), I get: ImportError: cannot import name 'documentai\_v1beta3' from 'google.cloud' (unknown location). The package installs fine but will not import.
Steps
- 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 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 thoughpip installsucceeded. Verify withimport 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.
When to use
You are seeing this: This happens in multiple environments, including a GCP notebook instance. Use this skill when you run into "google-cloud-documentai imports fail in GCP notebooks: kernel Python does not match pip".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: google-cloud-documentai 0.3.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 2 · 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>