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
|
1 Answer
Reset to default 0I 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
python
binary are you using? – ewokx Commented Mar 3 at 4:07py --version Python 3.12.3
– likejudo Commented Mar 3 at 15:27