Home > Net >  Can't solve "No module named 'numpy'" after hours of digging
Can't solve "No module named 'numpy'" after hours of digging

Time:08-09

I know this is a problem that's been asked here before, but I have tried all the solutions I found and not solved it. It's possible I'm not understanding the solutions, but I have tried my best.

I am teaching myself Python and it is slow going, so I don't understand a lot yet. I'm using VSCode as an IDE, Python version 3.10, and Windows 10. I only have the Python extension installed for VSCode. My project files are on a flash drive, D. I replaced a couple folder names with [Default Names] in the text below.

I keep trying to debug/run some code in VSCode and the very first line import numpy as np gives me the error Exception has occurred: ModuleNotFoundError - No module named 'numpy'.

But I know that's not true:

`PS D:\0-Career\Programming\PythonCoding\[ProjectFolder]> py -m pip install numpy   
Requirement already satisfied: numpy in c:\users\[UserID]\appdata\local\programs\python\python310\lib\site-packages (1.23.1)`

I tried the solution of going to

environment variables > system variables > "Path" > edit > new >
c:\users\[UserID]\appdata\local\programs\python\python310\

as well as C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Lib\site-packages\ and C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Scripts\ and I also tried adding a user variable called Python. Nothing appears to have changed as a result of these additions.

Some history if it's helpful: I first started by installing Python using the Microsoft Store. I used IDLE for a bit, and I used my command line to install pip and numpy. They worked for a little while. I later installed Visual Studio Code IDE. I ultimately have uninstalled the Microsoft Store version and installed the application from the Python site for Windows instead. I have also uninstalled and reinstalled it several times trying to fix my issues, and same for numpy. I also searched my C drive for "python" and burned everything from the past couple days and reinstalled and repaired it out of desperation. No luck.

I have tried to the best of my ability to uninstall everything and reinstall everything to start fresh, because numpy worked ever so briefly early on in IDLE, I think until I had installed the web download version of Python. I don't really understand environment variables, so I'm not sure what I'm doing or if I'm doing that wrong, or what needs to be restarted when I try something new, so it's possible I missed something.

Answers a 10 year old could understand would be appreciated! Or terminology I can easily research for an explanation of how to do it.

CodePudding user response:

  1. Ctrl Shift P open Command Palette

  2. choose Python:Select Interpreter

  3. Choose the right interpreter

CodePudding user response:

Go to SEE THIS IMAGE

Have Fun

CodePudding user response:

Try adding the variable PYTHONPATH to your system variables and add the following paths to this variable.

C:\PATH_TO_YOUR_PYTHON_INSTALL

C:\PATH_TO_YOUR_PYTHON_INSTALL\DLLs

C:\PATH_TO_YOUR_PYTHON_INSTALL\Lib

C:\PATH_TO_YOUR_PYTHON_INSTALL\Scripts

It should look something like this. Screenshot of Environment Variables

After you added the variable restart your VS Code and it should work. I hope this helps.

  • Related