10

I've just created a Google Cloud compute engine, installed google-cloud package with both pip and pip3, and I'm experiencing the following error when launching a script with python3

    from google.cloud import bigquery
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/__init__.py", line 35, 
in <module>
    from google.cloud.bigquery.client import Client
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/client.py", line 36, in
 <module>

(more traceback lines..)

    from pyasn1_modules.rfc2459 import Certificate
  File "/usr/local/lib/python3.5/dist-packages/pyasn1_modules/rfc2459.py", line 20, in <modu
le>
    from pyasn1.type import opentype
ImportError: cannot import name 'opentype'

On the compute engine the following packages are installed:

pyasn1==0.1.9
pyasn1-modules==0.2.1
google-cloud==0.30.0
google-cloud-bigquery==0.28.0

Which can be the problem here?

1

3 Answers 3

43

Posting my solution in case it helps someone else - this fixed it for me:

pip install --upgrade google-auth-oauthlib

More details discussed here: https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=198933&p=1241439#p1241439

0
20

It looks like you have an issue with pyasn1, so you could try installing a newer version (the latest is 0.4.2), or even reinstalling it manually with:

sudo apt-get --reinstall install python-pyasn1 python-pyasn1-modules

And if you are inside a virtualenv, use instead:

pip install pyasn1 pyasn1-modules
4
  • I have a similar problem on the raspberrypi 3, but this solution didn't seem to work. I have posted a question here: raspberrypi.org/forums/… Dec 1, 2017 at 11:55
  • Use the same command without the sudo, because for what I've seen, you are running the code inside a virtualenv, and then you will have to install the libraries inside the virtualenv, not in the external system.
    – dsesto
    Dec 1, 2017 at 11:58
  • 1
    My bad. I double checked, and in order to install inside a virtualenv, apt-get does not work. Try using this command instead, whe you are inside your virtualenv: pip install pyasn1 pyasn1-modules
    – dsesto
    Dec 1, 2017 at 12:01
  • 6
    @Yandrak3 Thanks for that - I found in the end that what I needed was pip install --upgrade google-auth-oauthlib. Dec 1, 2017 at 17:54
0

FWIW - Had the same issue - none of the above worked. I eventually discovered that if I did it under sudo it did work.

stracing the original - I found that I had a ~/.local directory which had a pyasn1 directory where it was trying to get the files from, but the opentype.py one did not appear there. When I deleted that whole directory - it started working.

I assume it was some sort of cache that was partial, and out-of-date???

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.