0

I was cloning a GitHub repository in GitHub Desktop, then moved the cloned file into a more convenient location. I then ran the GitHub repository and I got an error message:

ModuleNotFoundError: No module named 'numpy'

I thought this was odd, as I had already installed NumPy and used it regularly. I then went into a different Python file, which used NumPy and I was just using before perfectly fine and tried to run it. I got the same error again.

It seems that all my imports in every single Python file I have, in every location, no longer work. To verify that they are still installed, I ran: "pip install numpy", to which I got "Requirement already satisfied". What has happened? Python code without any imports works fine, and just anything which requires a library is broken.

It seems the error only occurs in Visual Studio Code - when I open a file with the Python IDE it works fine, but Visual Studio Code can’t find the module.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mercury
  • 298
  • 1
  • 11
  • Have you tried turning it off and on again? – topsail Dec 04 '22 at 22:27
  • That was the first thing i did. – Mercury Dec 04 '22 at 22:30
  • Are you using virtual environments? Is there some context here that might be relevant (like I'm connect to a remote vscode web session or what have you?) Are you using a notebook? Anything else ... there isn't much here to go on. You need to start a bit of trial and error basically. There is just no obvious answer to the question "python was working yesterday, why isn't it working today". – topsail Dec 04 '22 at 22:33
  • No virtual environments, just using python on my machine, not using a notebook or anything. It was all working fine until i tried to clone a repository in vs code (using the clone a repo feature), which closed the window. The import statements then break so i try to clone the repo from github desktop when i realise all the import statements in every single file are broken. – Mercury Dec 04 '22 at 22:36
  • Every single file in this "repository"? Or every single python file on your entire computer? – topsail Dec 04 '22 at 22:37
  • On my entire computer. – Mercury Dec 04 '22 at 22:38
  • You may need to check you system and user PATH variables. They may have been somehow destroyed. I don't see why cloning a repo would do any of this though - as far as I'm concerned, that's a red herring (unless the code in the repo itself is somehow "malicious" and created this problem (nefariously or not). – topsail Dec 04 '22 at 22:41
  • Quick update - the files do work in the python IDE, but when running in vscode the imports break – Mercury Dec 04 '22 at 22:47
  • You should try selecting a python interpreter: https://code.visualstudio.com/docs/python/environments#_work-with-python-interpreters – topsail Dec 04 '22 at 22:50
  • Have you tried `Python: Select Interpreter`? – MingJie-MSFT Dec 05 '22 at 02:20
  • What is the "the Python IDE"? [IDLE](https://en.wikipedia.org/wiki/IDLE)? [PyCharm](https://en.wikipedia.org/wiki/JetBrains#IDEs)? – Peter Mortensen Feb 09 '23 at 00:01
  • This is a mega duplicate. What is the canonical question? There are many many questions about Visual Studio Code-specific errors related to Python development. Some starting points for locating the canonical question: *[Visual Studio Code not recognizing Python import and functions](https://stackoverflow.com/questions/70362595/vscode-not-recognizing-python-import-and-functions)* and *[Visual Studio Code not running Python](https://stackoverflow.com/questions/58085966)* (the latter is not about imports, but it may or may not the same root cause) – Peter Mortensen Feb 09 '23 at 00:15

1 Answers1

0

Check if there is a virtual environment (like topsail said). NumPy might have been installed in a virtual environment.

If there is a virtual environment, check for a Scripts folder or a bin folder. If you find one, run activate or activate.bat.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • I dont believe there is a virtual enviroment, i dont think i've ever created one and my imports are in my standard python38 folder, is there any way to check? – Mercury Dec 04 '22 at 22:41