Problem when importing Pennylane

I have Python 3.7.4 and I’ve just installed the latest version of the package pennylane with pip install. Now when I try to import pennylane locally in a Jupyter Notebook, the following error is raised:

Traceback (most recent call last):

File “C:\Users\Usuario\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File “C:\Users\Usuario\AppData\Local\Temp/ipykernel_6848/2122156990.py”, line 1, in
import pennylane as qml

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane_init_.py”, line 35, in
import pennylane.templates

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\templates_init_.py”, line 21, in
from .embeddings import *

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\templates\embeddings_init_.py”, line 20, in
from .angle import AngleEmbedding

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\templates\embeddings\angle.py”, line 19, in
from pennylane.ops import RX, RY, RZ

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\ops_init_.py”, line 25, in
from .op_math import *

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\ops\op_math_init_.py”, line 60, in
from .prod import prod, Prod

File “C:\Users\Usuario\Anaconda3\lib\site-packages\pennylane\ops\op_math\prod.py”, line 324
operand_pauli_reps := [
^
SyntaxError: invalid syntax

This is my first time using PennyLane. Please help.

1 Like

Hi @Markint ,

Welcome to the Forum and welcome to PennyLane!

We stopped supporting Python 3.7 as of our latest PennyLane release. I would suggest that you create a new environment as follows and install PennyLane there:

Create a new conda environment with:conda create --name name_of_your_environment python=3.11
Activate the environment:conda activate name_of_your_environment
After this you can install the needed packages:python -m pip install pennylane

Please let me know if this works for you!

Hello Catalina,

Could you tell me more about the “name_of_your_environment”? Like, do we have to write in something else or do we have to type in a specific name that is different for each user?
I tried using the same “name_of_your_environment” and followed the same steps but the problem still persists for me. Anaconda has downgraded yet still calling the libraries gives the same issue.

Hello @Priyam_Srivastava ,

It’s the name of conda environment. You can chose any name for your environment.

Hi @imakash,

Thank you for the explanation, but the problem still persists for me.

Could you elaborate a bit more? What I should do after these steps in order to run pennylane locally from a jupyter notebook

Hi @Markint!

“name_of_your_environment” means that you could name your environment however you want :smile:

Since you’re still facing issues, could you please post the following information?

  1. The output of qml.about()
  2. The code that you’re running that is causing the error
  3. Your full error traceback

In case it’s useful you can also take a look at this video on how to install PennyLane.

Please let me know if you have any further questions!