I was going to use Braket in us-east1. I wanted to use qiskit, so I wanted to import the module, but an error occurred.
I referred to the following URL https://qiskit-community.github.io/qiskit-braket-provider/tutorials/3_tutorial_minimum_eigen_optimizer.html
Checking with !pip list, qiskit_algorithms is installed without any problem.
【code】
!pip install qiskit
!pip install qiskit-optimization
!pip install qiskit-algorithms
from qiskit import QuantumCircuit, transpile
from qiskit.quantum_info import SparsePauliOp
from qiskit.primitives import Sampler
from qiskit_aer import AerSimulator
from qiskit_optimization import QuadraticProgram
from qiskit_algorithms.minimum_eigensolvers import QAOA
from qiskit_algorithms.optimizers import COBYLA
from qiskit_algorithms import NumPyMinimumEigensolver
from qiskit_optimization.algorithms import MinimumEigenOptimizer
【output】
ModuleNotFoundError Traceback (most recent call last)
Cell In[7], line 10
4 from qiskit_aer import AerSimulator
5 # from qiskit_optimization import QuadraticProgram
6 # from qiskit_algorithms.minimum_eigensolvers import QAOA
7 # from qiskit_algorithms.optimizers import COBYLA
8 # from qiskit_algorithms import NumPyMinimumEigensolver
9 # from qiskit_optimization.algorithms import MinimumEigenOptimizer
---> 10 import qiskit_optimization
ModuleNotFoundError: No module named 'qiskit_optimization'
How can I install qiskit_algorithms and qiskit_optimization without problems?
I have tried the following.
- Verify that the module is installed with a !pip list
- Restart kernel
- Start another notebook
- Verify that the installed path of the package is correct
- Confirm that the module works fine in the local environment
The error is straight up telling you that the module isn't installed, so we can work with that, or else there's some issue with how you've installed it. This can often be something like permissions or it not running on the same Python environment. Confirm you've got the latest upgrades.
If you need to install this on the environment where your kernel is running, try the following. This is worth trying as you are getting a clear error that the package isn't installing where it is trying to run, so let's rule this out.
Now keep it simple for sake of testing an import only the necessary modules.
That should do it. Make sure to run it in an environment where you have the necessary permissions to install packages using pip. If you are using a Jupyter notebook, you might want restart the kernel and run the cells again to ensure that the new package is imported correctly. I've had this issue before so hopefully my fixes work for you too.