python - Getting Numpy error on VSCode (Windows11) even though numpy is installed - Stack Overflow

reference:I created file hello.pyimport numpy as npmsg = "Roll a dice!"print(msg)print(np.r

reference:

I created file hello.py

import numpy as np

msg = "Roll a dice!"
print(msg)

print(np.random.randint(1,9))

In VSC I go to the Play button at the top and click one of the options for instance, "Run Python File In..." - they all give the same error.

 line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

following instructions, I did

py -m pip install numpy
WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) Requirement already satisfied: numpy in c:\python312\lib\site-packages (2.1.3) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages)

Running it again, I still get

ModuleNotFoundError: No module named 'numpy'

In the terminal window, I

python -c "import numpy; print(numpy.__version__)" 
2.1.3

reference: https://code.visualstudio/docs/python/python-tutorial#_start-vs-code-in-a-project-workspace-folder

I created file hello.py

import numpy as np

msg = "Roll a dice!"
print(msg)

print(np.random.randint(1,9))

In VSC I go to the Play button at the top and click one of the options for instance, "Run Python File In..." - they all give the same error.

 line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

following instructions, I did

py -m pip install numpy
WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) Requirement already satisfied: numpy in c:\python312\lib\site-packages (2.1.3) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ (C:\Python312\Lib\site-packages) WARNING: Ignoring invalid distribution ~ip (C:\Python312\Lib\site-packages)

Running it again, I still get

ModuleNotFoundError: No module named 'numpy'

In the terminal window, I

python -c "import numpy; print(numpy.__version__)" 
2.1.3
Share Improve this question edited Mar 3 at 15:22 likejudo asked Mar 3 at 3:02 likejudolikejudo 3,7358 gold badges59 silver badges118 bronze badges 3
  • How are you running your script? Which python binary are you using? – ewokx Commented Mar 3 at 4:07
  • @ewokx In VSC I go to the Play button at the top and click one of the options for instance, "Run Python File In..." - they all give the same error. – likejudo Commented Mar 3 at 15:21
  • py --version Python 3.12.3 – likejudo Commented Mar 3 at 15:27
Add a comment  | 

1 Answer 1

Reset to default 0

I did a CTRL-Shift-P and this brought up a dropdown menu. I chose Python - Select Interpreter Picked Global, Ran the Program, Same error. then I Switched to Recommended Interpreter and voila, it worked!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111415a4611874.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信