
Quantum Computing in Practice with Qiskit® and IBM Quantum Experience®
By :

With your Python environment prepared and ready to go, and your IBM Quantum Experience® account set up, you can now use pip
to install the Qiskit® Python extension. The process should take about 10 minutes or so, after which you can use your Python command line, or your favorite Anaconda Python interpreter to start writing your quantum programs.
This recipe provides information about the generic way to install Qiskit® and does not go into any detail regarding operating system differences or general installation troubleshooting.
For detailed information about the most current requirements for Qiskit® installation, see the Qiskit® requirements page at https://qiskit.org/documentation/install.html.
$ conda create -n environment_name python=3
This will install a set of environment-specific packages.
$ conda activate environment_name
Your Command Prompt should now include the name of your environment; I used something like this for my own environment with the name packt_qiskit
:
(packt_qiskit) Hassis-Mac:~ hassi$
Nomenclature
In this chapter, I will print out the full prompt like this (environment_name) … $
to remind you that you must execute the commands in the correct environment. In the rest of the book, I will assume that you are indeed in your Qiskit-enabled environment and just show the generic prompt: $
.
pip
update.To install Qiskit®, you must use pip
as Qiskit® is not distributed as conda
packages. The latest Qiskit® requires pip 19 or newer.
If you have an older version of pip
, you must upgrade using the following command:
(environment_name) … $ pip install -U pip
So, with everything set up and prepared, we can now get on to the main course, installing the Qiskit® code in your environment. Here we go!
(environment_name) … $ pip install qiskit
Failed wheel build
As part of the installation, you might see errors that the wheel failed to build. This error can be ignored.
Open Python:
(environment_name) … $ python3
Import Qiskit®:
>>> import qiskit
This is a little bit exciting; we are going to use Qiskit® code for the first time. Granted, not exactly for programming a quantum computer, but at least to make sure that we are now ready to start programming your quantum programs.
List the version details:
>>> qiskit.__qiskit_version__
This should display the versions of the installed Qiskit® components:
{'qiskit-terra': '0.15.2', 'qiskit-aer': '0.6.1', 'qiskit-ignis': '0.4.0', 'qiskit-ibmq-provider': '0.9.0', 'qiskit-aqua': '0.7.5', 'qiskit': '0.21.0'}
Congratulations, your Qiskit® installation is complete; you are ready to go!
By using pip
install
from your virtual environment, you can install Qiskit® in just that environment, which will then stay isolated from the rest of your Python environment.
Qiskit® also comes with some optional visualization dependencies to use visualizations across the Qiskit® components. You can install these with the following command:
(environment_name) … $ pip install qiskit[visualization]
Note
If you are using the zsh shell you must enclose the component in quotes:pip install 'qiskit[visualization]
'
For a quick introduction to Anaconda environments, see Managing environments in the Anaconda docs: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html.
This book does not, in any way, act as a Qiskit® installation troubleshooting guide, and you might conceivably run into issues when installing it, depending on your local OS, versions, and more.
But fear not, help is on the way. Here are a couple of good and friendly channels on which to reach out for help: