JackHidary / quantumcomputingbook

Companion site for the textbook Quantum Computing: An Applied Approach
789 stars 215 forks source link

Error when importing Cirq #7

Closed yogeshriyat closed 4 years ago

yogeshriyat commented 4 years ago

Hello, the following error occurred when I tried to implement the code on p. 65 in Jupyter Notebook. Any guidance?

AttributeError: module 'googleapiclient' has no attribute 'version'

I did read up on SO:

I had the same error and changing the import fixed it for me. The developers recommend importing from googleapiclient instead of apiclient.

So you will need to change from apiclient import errors to from googleapiclient import errors

But it looks like this change would be to the init.py file ? I was thinking I could go edit this file, but didn't know if there was some other way?

This is the error text: `--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

in 1 # Import the Cirq package ----> 2 import cirq 3 4 # Pick a qubit 5 qubit = cirq.GridQubit(0,0) ~/Desktop/Anaconda/anaconda3/envs/cirq/lib/python3.8/site-packages/cirq/__init__.py in 36 study, 37 ) ---> 38 from cirq import ( 39 # Core 40 circuits, ~/Desktop/Anaconda/anaconda3/envs/cirq/lib/python3.8/site-packages/cirq/google/__init__.py in 40 ) 41 ---> 42 from cirq.google.engine import ( 43 Calibration, 44 Engine, ~/Desktop/Anaconda/anaconda3/envs/cirq/lib/python3.8/site-packages/cirq/google/engine/__init__.py in 19 Calibration,) 20 ---> 21 from cirq.google.engine.engine import ( 22 Engine, 23 JobConfig, ~/Desktop/Anaconda/anaconda3/envs/cirq/lib/python3.8/site-packages/cirq/google/engine/engine.py in 36 import warnings 37 ---> 38 from apiclient import discovery, http as apiclient_http 39 from apiclient.errors import HttpError 40 from apiclient.http import HttpRequest ~/Desktop/Anaconda/anaconda3/envs/cirq/lib/python3.8/site-packages/apiclient/__init__.py in 20 from googleapiclient import schema 21 ---> 22 __version__ = googleapiclient.__version__ 23 24 _SUBMODULES = { AttributeError: module 'googleapiclient' has no attribute '__version__' `
rmlarose commented 4 years ago

You can run pip install google-api-python-client==1.8.0 (after installing Cirq if you haven't already). Nothing needs to be changed in init or any other files.

This issue is with Cirq (see https://github.com/quantumlib/Cirq/issues/2926) and will be fixed when the new Cirq version is released.

rmlarose commented 4 years ago

Note this is now fixed by google-api-python-client version 1.8.2. Installing Cirq in a new virtual environment (or reinstalling Cirq) works properly.

yogeshriyat commented 4 years ago

Hmm I just installed Cirq yesterday in a virtual environment, but I’ll look into it. Thank you.

On Apr 22, 2020, at 8:34 AM, Ryan LaRose notifications@github.com wrote:

 Note this is now fixed by google-api-python-client version 1.8.2. Installing Cirq in a new virtual environment (or reinstalling Cirq) works properly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

yogeshriyat commented 4 years ago

I uninstalled Anaconda. It was giving me trouble with installing packages in virtual environments. So for the exercise on p.65 I get the correct output now, but I get the following text also. I do not know what to make of it:

/Users/Yogesh/Cirq/lib/python3.7/site-packages/ipykernel_launcher.py:10: DeprecationWarning: Circuit.from_ops was used but is deprecated.
It will be removed in cirq v0.8.0.
use `cirq.Circuit(*ops)` instead.

  # Remove the CWD from sys.path while we load stuff.

I actually tried using cirq.Circuit(*ops) instead of cirq.Circuit.from_ops, but it gave an error that said ops was not recognized.

`--------------------------------------------------------------------------- NameError Traceback (most recent call last)

in 6 7 #Create a circuit ----> 8 circuit = cirq.Circuit(*ops)([ 9 cirq.X(qubit), # NOT 10 cirq.measure(qubit, key='m') # Measurement NameError: name 'ops' is not defined`
rmlarose commented 4 years ago

The first example just says the method Circuit.from_ops will be removed in Cirq v0.8.0. We'll update the programs in here when appropriate. The second error is because the variable ops was never defined.