-1

I am using qiskit (I am an absolute beginner with some experience with Java and know basic python) but when I tried to run an example code which uses numpy it gave me this error. I tried reinstalling it but it gave me the same error.

I have tried installing and reinstalling it but it didnt work

import numpy as np
from cqc.pythonLib import CQCConnection, qubit
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
from qiskit.tools.visualization import circuit_drawer
from qiskit.quantum_info import state_fidelity
from qiskit import BasicAer

Traceback (most recent call last):
  File "/home/nikhil/.local/lib/python3.6/site-packages/numpy/core/__init__.py", line 40, in <module>
    from . import multiarray
  File "/home/nikhil/.local/lib/python3.6/site-packages/numpy/core/multiarray.py", line 12, in <module>
    from . import overrides
  File "/home/nikhil/.local/lib/python3.6/site-packages/numpy/core/overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nikhil/.local/lib/python3.6/site-packages/fghjkl.py", line 1, in <module>
    import numpy as np
  File "/home/nikhil/.local/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/home/nikhil/.local/lib/python3.6/site-packages/numpy/core/__init__.py", line 71, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using /usr/bin/python3.7),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

     Note: this error has many possible causes, so please don't comment on
     an existing issue about this - open a new one instead.

Original error was: No module named 'numpy.core._multiarray_umath'
kindall
  • 178,883
  • 35
  • 278
  • 309
invalidexplorer
  • 11
  • 1
  • 1
  • 4
  • Run ```python --version``` and ```pip freeze | grep numpy``` to get the versions of python and numpy. You installed it via pip install? – Victor Ruiz Jul 04 '19 at 17:18
  • Also did you follow the instructions in the error message? – Victor Ruiz Jul 04 '19 at 17:20
  • Did you follow all the instructions in the "PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE" message? The part about checking which Python you're using and checking your PATH and PYTHONPATH seems relevant. Particularly, it says you're using Python 3.7, but the stack trace shows Python trying to import from Python 3.6 directories. – user2357112 Jul 04 '19 at 17:20
  • Execute the next command: ```python -c "import sys; print(sys.path)"``` Check that .../python3.7/site-packages is on the sys.path – Victor Ruiz Jul 04 '19 at 17:26
  • If you are going to reinstall the packages, I'd suggest first doing 'numpy' and testing it alone. The do `qiskit` etc. Some times packages require older `numpy` versions, and that can cause conflicts. – hpaulj Jul 04 '19 at 20:32
  • Yes I have been using Python 3.6 directories as the modules I want to use are there. Using 3.7 gives me error. How can I configure numpy according to 3.6? – invalidexplorer Jul 05 '19 at 14:15
  • @VictorRuiz I tried that command with both python and python3, I had python 2.7 and python 3.6 with each of the following. Why isnt is showing 3.7 when I use python3? – invalidexplorer Jul 05 '19 at 18:02
  • Create a virtualenv with version 3.6: ```virtualenv --python=python3.6 test```. Then print again sys.path and try to install and import numpy – Victor Ruiz Jul 05 '19 at 19:41
  • @VictorRuiz Hi! I changed the virtualenv and its still showing it to be python 3.6 instead of 3.7, I tried installing numpy but it says that it is already in the directory of 3.6 (Requirement already satisfied: numpy in ./.local/lib/python3.6/site-packages). Is importing numpy giving a problem because its looking for it in 3.7 instead of 3.6? – invalidexplorer Jul 06 '19 at 10:34
  • before installing numpy and excute your script, make sure to activate the virtualenv: ```./test/bin/activate``` (the virtualenv you created should have python 3.6 version). Check it with ```python3 --version``` – Victor Ruiz Jul 06 '19 at 11:00
  • 1
    @VictorRuiz Got the mistake, Pycharm was using 3.7 as the project interpreter, changed it to 3.6. This fixed the previous problem. Thank you so much for helping! – invalidexplorer Jul 06 '19 at 11:38

1 Answers1

0

Try to upgrade the numpy:

pip install --upgrade numpy

or uninstall it and reinstall it again:

pip uninstall numpy
pip install numpy
mohd4482
  • 1,788
  • 14
  • 25