I have successfully installed qiskit. However, when I try to run a simulation I get the error "No module named 'qiskit'
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute
How can I get or enable this module?
Just install by using pip package pip3 install qiskit You can find the pip3.exe under the python installation.
Try command pip install qiskit
or pip3 install qiskit
in cmd or Anaconda Prompt to install the qiskit module. Then try running the command you used.
If it's still not working check whether your notebook is working in the same location where you installed the qiskit module.
Tip: Use from qiskit import *
as it saves time and imports all the packages in qiskit.
Alternative: You can also use the jupyter notebook in IBM Quantum Experience.
from [package] import *
is considered to be a bad practice in Python as it might imports a lot of things into the global namespace and it makes the code less readable (if you have 2 such constructs, someone that does not know the packages have no way of finding which one included the thing he/she is interested in).
$\endgroup$
Commented
Jul 13, 2021 at 8:44
I believe this is a path issue. As already mentioned
pip3 install qiskit
will install the full package and configure the paths for you.
You can find the search paths for all Python modules by
import sys
print(sys.path)
If the full path to your Qiskit package is full/path/to/qiskit
and '/full/path/to'
is not in sys.path
, then you need to append it by
sys.path.append('full/path/to')
in the script you are running. If you are running on Linux, you can write
export PYTHONPATH=/full/path/to:$PYTHONPATH
in the .bashrc
file so that you don't need to set the path every time.