Cannot Import Pennylane

I just installed Pennylane v31 (given all the dependencies are satisfied concerning python, torch and jax). However, I cannot import Pennylane and get the following error message :

AttributeError: module 'jax.experimental.sparse' has no attribute 'BCSR'

And, this has to do with the class ´´ParametrizedHamiltonianPytree´´.

Hi Kalyani,
This error is most likely due to an older jax installation in the environment in which you are trying to install pennylane. Note that jax is not a dependency of PennyLane, so when you are installing pip install -r requirements.txt, this does not update jax to the right version.
I’d recommend to manually pip install --upgrade jax if you want to use jax and pennylane. Or, alternatively, install pennylane in an environment that does not have jax installed (then, too, this error wont be raised).

Let me know if this works!
Kind regards, Korbinian


Hello! Thanks a lot, it works perfectly fine :slight_smile: