ImportError: cannot import name 'shape'

I’m trying to import Pennylane for the first time and I keep getting this error for ‘import pennylane as qml’:

ImportError Traceback (most recent call last)
----> 1 import pennylane as qml

/usr/local/lib/python3.6/dist-packages/pennylane/ in
30 import pennylane.operation
31 import pennylane.qnn
—> 32 import pennylane.templates
33 from pennylane._device import Device, DeviceError
34 from pennylane._grad import grad, jacobian, finite_diff

/usr/local/lib/python3.6/dist-packages/pennylane/templates/ in
18 from .broadcast import *
19 from .decorator import *
—> 20 from .layer import *
21 from .layers import *
22 from .embeddings import *

/usr/local/lib/python3.6/dist-packages/pennylane/templates/ in
17 # pylint: disable-msg=too-many-branches,too-many-arguments,protected-access
18 from pennylane.templates.decorator import template as temp
—> 19 from pennylane.math import shape

ImportError: cannot import name ‘shape’

EDIT: I just found a solution. For some reason the later package versions all have import errors. If anyone else gets this run:

pip uninstall pennylane --yes

pip install pennylane==0.12.0

Best of luck!

Hi @J_Sheppard, welcome to the forum!

Thank you very much for adding the solution. We will look into why this is happening.

Don’t hesitate to post any new questions that you may have!

Hi @J_Sheppard, the problem is happening because you have Python version 3.6.

Try downloading a newer Python version and then the latest PennyLane releases should work.

Please let me know if this helps!

Got the same error. So, created a new environment with Python3.8 and it imported fine> Sharing the commands used.
​conda create -n penny python=3.8
conda activate penny
​ pip install pennylane --upgrade
Thank you

Hi @raghavv, I’m glad you were able to solve it!

I do recommend that you always use a virtual environment with your projects.

Let us know if you have any further questions and enjoy using PennyLane!

thank you @CatalinaAlbornoz for the kind information. I have been trying to run some quantum chemistry calculation, will let you know . Thank you.

Just an FYI, on the installation webpage the banner still says “PennyLane supports Python 3.6 or newer.” – this might be confusing for some people doing the install

oops, nice catch @EvanPeters, I’ll correct this.