I have an IBM Quantum account. How can I save the IBM Quantum API token to local environment so that I can access services including real quantum systems, simulators and Qiskit Runtime programs on my local machine using Qiskit?
Create an IBM Quantum account or log in to your existing account by visiting the IBM Quantum login page.
Copy (and/or optionally regenerate) your API token from your IBM Quantum account page.
Take your token from step 2, here called
MY_API_TOKEN, and run:
from qiskit import IBMQ IBMQ.save_account('MY_API_TOKEN')
The command above stores your credentials locally in a configuration file called
qiskitrc. By default, this file is located in
$HOMEis your home directory. If you are still using
Qconfig.py, please delete that file and run the command above.
I personally utilize python Keyring package for storing and retrieving the secrets on local OS. It leverages the OS provided security and supports mac, windows and linux os backends. This prevents the storage of secrets into plain text and makes notebooks portable.
If you are on windows os, you can store the credentials into windows credential manager and retrieve it using the
import keyring # store username & password keyring.set_password("my_ibmq_token", "username", "thetoken") # retrieve username & password username = keyring.get_password("my_ibmq_token", "username") password = keyring.get_password("my_ibmq_token", "password")