I have successfully installed the Qiskit in Anaconda by using pip install qiskit.

But I can't import Qiskit and get the following error.

OSError                                   Traceback (most recent call last)
<ipython-input-5-578b7f7e9727> in <module>
----> 1 import qiskit

~\anaconda3\envs\quantum_computing\lib\site-packages\qiskit\__init__.py in <module>
     30 # The main qiskit operators
---> 31 from qiskit.circuit import ClassicalRegister
     32 from qiskit.circuit import QuantumRegister
     33 from qiskit.circuit import AncillaRegister

~\anaconda3\envs\quantum_computing\lib\site-packages\qiskit\circuit\__init__.py in <module>
    212    random.random_circuit
    213 """
--> 214 from .quantumcircuit import QuantumCircuit
    215 from .classicalregister import ClassicalRegister, Clbit
    216 from .quantumregister import QuantumRegister, Qubit, AncillaRegister, AncillaQubit

~\anaconda3\envs\quantum_computing\lib\site-packages\qiskit\circuit\quantumcircuit.py in <module>
     23 from collections import OrderedDict, defaultdict
     24 from typing import Union
---> 25 import numpy as np
     26 from qiskit.exceptions import QiskitError
     27 from qiskit.util import is_main_process

~\AppData\Roaming\Python\Python38\site-packages\numpy\__init__.py in <module>
    139     # Allow distributors to run custom init code
--> 140     from . import _distributor_init
    142     from . import core

~\AppData\Roaming\Python\Python38\site-packages\numpy\_distributor_init.py in <module>
     24                 # NOTE: would it change behavior to load ALL
     25                 # DLLs at this path vs. the name restriction?
---> 26                 WinDLL(os.path.abspath(filename))
     27                 DLL_filenames.append(filename)
     28     if len(DLL_filenames) > 1:

~\anaconda3\envs\quantum_computing\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    380         if handle is None:
--> 381             self._handle = _dlopen(self._name, mode)
    382         else:
    383             self._handle = handle

OSError: [WinError 193] %1 is not a valid Win32 application

So what should I do to solve this problem?

  • $\begingroup$ Reading through the error message it looks like this is a problem with your numpy installation and not qiskit. Also I don't think you usually install packages to anaconda via "pip install" usually it is "conda install". Although as a disclaimer I don't use anaconda so maybe this is a wrong impression I have. $\endgroup$ – Rammus Nov 19 at 9:04
  • 4
    $\begingroup$ I’m voting to close this question because belongs to stackoverflow. For example: stackoverflow.com/questions/55185236/… $\endgroup$ – luciano Nov 19 at 19:49

Try the following command and get back if errors persist

from qiskit import *

| improve this answer | |
  • $\begingroup$ When you have enough reputation, please use comment for short answers. $\endgroup$ – Martin Vesely Nov 19 at 9:49

The issue you're seeing is actually unrelated to qiskit itself. It's a conflict between package versions in your anaconda and the system python install. What it looks like from the stack trace there is that you're running in the anaconda environment and it is loading numpy from a different python environment (which was not installed with anaconda). This is causing a conflict when the anaconda's environment python is trying to load it. This could be because of win32 vs win64 binary issue or some other dll incompatibility between the 2 environments. What I would recommend is if you want to continue using conda is to create a new conda environment and leverage conda install to install numpy and scipy then pip install qiskit. So something like:

conda create new-qiskit
conda activate new-qiskit
conda install numpy scipy
pip install qiskit

or what I typically do when testing on windows is to just not use conda and create a normal python virtualenv and pip install qiskit directly with that.

| improve this answer | |
  • $\begingroup$ Your solutions didn't work sir. $\endgroup$ – Mg Sein Nov 20 at 10:23

OS Error refers to an operating system error. On this page, you can see that qiskit is tested on 64-bit os solely.

The report says that your operating system is 32-bit, this should be the reason. When I was first pip install qiskit, it fails. Later I changed my python from a 32-bit version to a 64-qubits one and then pip succeeds(my laptop is 64-bit). If your CPU is 64-bit you can use a windows 64-bit virtual machine, to see more detail follow this stack overflow link.

If you cannot you the win64 virtual machine maybe you can rent a VPS or submit your script to the IBM Q server.

| improve this answer | |
  • $\begingroup$ I don't know how qiskit works on Linux, but I think for windows it simply doesn't have a 64-bit version. $\endgroup$ – Yitian Wang Nov 19 at 11:49

Reinstalling numpy didn't work for me.

I delete the C:\Users\USERNAME\AppData\Roaming\Python\Python38\* folder because that was left behind by a previous Python which I had uninstalled.

And this work for me.

Thanks to everyone who all answered my questions and I appreciate it.

| improve this answer | |
New contributor
Mg Sein is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.