skip to Main Content

I have installed numpy using pip
also the same code below works smoothly in python IDLE but not in vs code

here it is

I wrote:

import numpy as np
np.ones(8)

and the error shows:

PS C:UsersanshuDocumentsVScode Python> python -u "c:UsersanshuDocumentsVScode Pythonextra.py"
Traceback (most recent call last):
  File "c:UsersanshuDocumentsVScode Pythonextra.py", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'
PS C:UsersanshuDocumentsVScode Python> 

i have checked many questions and they usually say install numpy using, pip install numpy.
or there is a things in another IDEs like anaconda (which i do not install) or pycharm etc.

i just wanted to resolve this problem in vs code not in any other IDE.

2

Answers


  1. If you’re using python -u file I would suggest checking the python you’re using is the same one you installed numpy to, it could be using a different installation.

    Many users often have several python installations or virtual environments (more on that here: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/) and that can cause conflicts in aliases and required dependencies and where they are installed.

    I’d recommend ensuring you install numpy to same installation you’re running from, to do that you can do:
    python -m pip install numpy

    See here for more information about using pip for a certain python installation: https://pip.pypa.io/en/stable/user_guide/#running-pip

    Login or Signup to reply.
  2. This problem was usually caused by incorrect python interpreter.

    You could try to use shortcuts Ctrl+Shift+P and type "Python: Select Interpreter" to choose the python interpreter which you installed the package in.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search