ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 import pennylane as qml
22 from networkx.classes import filters
23 from networkx.classes import *
—> 24 from networkx.classes import _dispatch
26 from networkx import convert
ImportError: cannot import name ‘_dispatch’ from ‘networkx.classes’ (/usr/local/lib/python3.10/dist-packages/networkx/classes/init.py)
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
“Open Examples” button below.
Hey @Eleonora_Panini! Welcome to the forum
Interesting… I’m not able to replicate this when I open a Google collab session:
Can you try restarting your browser, opening a new collab session, and try installing pennylane and networkx again?
I tried with Anaconda and I installed pennylane, but when I import the package (import pennylane) I get this error:
if (p_rep := new_op._pauli_rep) is not None:
SyntaxError: invalid syntax
Do you have any idea?
Thank you for asking this question!
To install PennyLane locally it’s strongly recommended that you create a new virtual environment to prevent you from having any installation issues. You can create a virtual environment with Conda and install PennyLane as follows:
- Install Anaconda following the instructions here.
- Open your terminal (mac) or command line (Windows).
- Create a new Conda environment with:
conda create --name <name_of_your_environment> python=3.10
- Activate the environment with:
conda activate <name_of_your_environment>
- Install PennyLane with:
python -m pip install pennylane
- Install other useful packages with:
python -m pip install pennylane jupyter matplotlib
Note that you will be installing 3 packages here: PennyLane, Jupyter, and Matplotlib. You don’t necessarily need the three of them but they tend to be useful. Also, note that where it says
<name_of_your_environment> you can choose any name that you want. After this you can write
jupyter notebook in your terminal/command line and you will be ready to create programs using PennyLane.
You can also watch the video here for detailed PennyLane installation instructions.
If you have trouble installing PennyLane locally, you can use Google Colab and open a new notebook there. Run the following at the beginning of your notebook (including the exclamation mark):
!pip install pennylane
If you’re still facing issues please post your code and your full error traceback.
I hope this helps you get started!
Thank you, now pennylane works also in local, but I get the same error of the code in Google Colab when I run the quantum gan demo adapted on my dataset : stack overflow. (see the other post)
That’s great to hear @Eleonora_Panini ! Let’s continue the conversation about the GAN in the other thread.