mirror of https://github.com/Qiskit/qiskit.git
Add warning on Aer and IBMQ ImportError (#2842)
* Add warning on Aer and IBMQ ImportError This commit adds a warning whenever qiskit is imported if it can't import qiskit-aer or qiskit-ibmq-provider. Right now if a user installs terra and either does not install aer or the ibmq-provider, or also equally as likely installs them but python packaging messes up the namespace and there is no indication that these features are missing until they go to use qiskit.Aer, or qiskit.IBMQ. To address this commit adds a warning that will only be displayed once on the first import of anything from the qiskit namespace in a python process, using python's stdlib warning mechanism (which is configurable and suppressible). This will hopefully remove the surprise when users try to use Aer or IBMQ like in documentation and tutorials and they just get an empty AttributeError. Related #2483 * Update warning message * Fix review comments and change warning class
This commit is contained in:
parent
a2d1d412c0
commit
6795f5399f
|
@ -18,6 +18,7 @@
|
|||
"""Main Qiskit public functionality."""
|
||||
|
||||
import pkgutil
|
||||
import warnings
|
||||
|
||||
# First, check for required Python and API version
|
||||
from . import util
|
||||
|
@ -50,12 +51,17 @@ from qiskit.providers.basicaer import BasicAer
|
|||
try:
|
||||
from qiskit.providers.aer import Aer
|
||||
except ImportError:
|
||||
pass
|
||||
warnings.warn('Could not import the Aer provider from the qiskit-aer '
|
||||
'package. Install qiskit-aer or check your installation.',
|
||||
ImportWarning)
|
||||
# Try to import the IBMQ provider if installed.
|
||||
try:
|
||||
from qiskit.providers.ibmq import IBMQ
|
||||
except ImportError:
|
||||
pass
|
||||
warnings.warn('Could not import the IBMQ provider from the '
|
||||
'qiskit-ibmq-provider package. Install qiskit-ibmq-provider '
|
||||
'or check your installation.',
|
||||
ImportWarning)
|
||||
|
||||
from .version import __version__
|
||||
from .version import __qiskit_version__
|
||||
|
|
Loading…
Reference in New Issue