3

I've created a new virtual environment in Anaconda and installed several packages using pip (namely, numpy, scipy, matplotlib, qiskit and maybe 1 or 2 more). I open the interpreter and try to import a module from Qiskit:

from qiskit import Aer

As a result, I get ImportError: cannot import name 'Aer'. My understanding is that either Qiskit 0.7 has a different structure of the modules (which I can't find anywhere in the documentation) or that my setup has a conflict of some kind. How do I know what is the case and how do I fix it?

EDIT: I have a dual boot system. The problem occurs on Anaconda on Windows 10, but doesn't on Ubuntu 18 on pure Python. So I think it has to be something with Anaconda rather than Qiskit.

EDIT 2: I have made a clean install of Python (without Anaconda) and the problem persists.

Alexey Uvarov
  • 143
  • 1
  • 7
  • Thank you for your answers guys! I barely even remember how I got out of this issue :( I think I raised an issue on qiskit's github page, and they suggested rebuilding it from source. I decided not to bother and keep doing everything on Linux. Now, though, the question must be obsolete at all because Qiskit's current version is much higher than 0.7 – Alexey Uvarov Apr 14 '20 at 08:21

4 Answers4

4

I had the same problem. I looked at the repository on GitHub of qiskit terra (https://github.com/Qiskit/qiskit-terra) and in the examples they use BasicAer. So, I figure that they renamed to module.

2

Indeed, I also had the same issue: Anaconda 3 on Windows 10. I later had the same trouble on a travis CI python 3.5 & 3.6 build image. For both I had a similar yet different solution. The similarity lies in the fact that it seems to be a missing dependency. The code of the simulator is written in C++ or maybe now Cython. So they use some dependencies that your setup may not have. This is where the similarities ended. What I did:

Windows 10 / Anaconda setup

With the dependency walker http://www.dependencywalker.com/ I found out that the openblas.dll is missing as dependency. Interesting enough, in the legacy simulators the qiskit team provided one. So you could either use this one or download (and rename!!) the latest binary from https://www.openblas.net/. Then copy it into your site-packages folder. You know you got the right folder when you find files with the names of the sort

  • unitary_controller_wrapper.pyd
  • statevector_controller_wrapper.pyd
  • qasm_controller_wrapper.pyd

Travis CI python >= 3.5 image

Here on the other hand I was at loss with the same explanation (and solution), so I looked into qiskit-aer repository's .travis setup. Here you see, that they use (among other directives) - sudo apt-get -y install g++-7 - sudo apt-get -y install libopenblas-dev I used this for my travis CI and - voilà - it works. Prior to this I used ldd and readelf and it pointed to some library that I don't recall but it seems like qiskit-aer depends on it and you get this with a more recent version of g++.

I wonder if this will solve your issues.

1

To solve this try to import Aer separately. For example:

from qiskit import QuantumCircuit, QuantumRegister, execute, Aer, IBMQ

I hope this answers your question

1

Try the following:

from qiskit.providers.aer import Aer 
Anton Pomieshchenko
  • 1,680
  • 2
  • 7
  • 18