0

I'm using VS Code with code runner and have installed numpy, however, when I try to run it with code runner I get the message: No module named 'numpy'. I looked into my settings.json and the command for python is python3 -u and when executing the respective file with python3 -u file.py in the terminal, everything works fine. What could cause the problem on the side of VS Code?

starball
  • 20,030
  • 7
  • 43
  • 238
Hilberto1
  • 248
  • 1
  • 3
  • 10
  • I would recommend installing own `virtualenv` target directory and install all of the packages there. Or switch to pycharm idea. Agreed, it's not the solution, and I like coding in vscode or vim even. but percent of troubles is much less there – Vova Mar 10 '21 at 07:34

1 Answers1

0

It is recommended that you use the command (python --version or pip --version) to check whether the python currently used in the terminal is the same as the one in the lower left corner of VS Code. And clean up the terminal information, and then re-run the code:

enter image description here

enter image description here

In addition, please try to comment out the settings related to "code runner" in "settings.json" and reload VS Code.

Update:

For the problem that the python used in the terminal is different from the python displayed in the lower left corner of VS Code:

If you are using the global python environment, please try to change the first of the python environment variables to the python you want to use, and then reopen VS Code.

enter image description here

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
  • sorry for not answering, I somehow didn't recognise that an answer was posted. I actually found out the above by myself and installed the respective modules in the vscode terminal. The one question remaining is: How can I make VSCode use the version I see in the bottom line of vscode as expected? – Hilberto1 Mar 15 '21 at 13:13
  • @Hilberto1 -Please select the python environment you need in the lower left corner of VS Code, and then use the shortcut key " Ctrl+Shift+` " to open a new VS Code terminal, and it will automatically enter the selected environment. It is recommended that you close or delete the previously used VS Code terminal to avoid confusion. – Jill Cheng Mar 16 '21 at 01:17
  • yes but unfortunately this doesn't resolve the issue (that's also one of the many things I've already tried) – Hilberto1 Mar 16 '21 at 14:55
  • @Hilberto1 -What is the problem you are encountering now? Is the installed module still unusable? – Jill Cheng Mar 17 '21 at 01:19
  • as I mentioned, I solved my original the problem partially by manually installing the different modules in the vs console, but if I do `python --version` I still get a different from that in the bottom line. – Hilberto1 Mar 17 '21 at 10:21
  • @Hilberto1 -Please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, it will automatically enter the selected python environment (shown in the lower left corner of VS Code). – Jill Cheng Mar 18 '21 at 01:32
  • that unfortunately didn't work, the version is still not the one in the bottom line – Hilberto1 Mar 18 '21 at 11:54
  • @Hilberto1 -What [python environment](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment) do you use in VS Code? If it is a global python environment, please try to change the first of the python environment variables to the python you want to use, and then reopen VS Code. – Jill Cheng Mar 19 '21 at 01:38
  • where can I change the python environment variables? (I'm using a global environment) – Hilberto1 Mar 19 '21 at 17:28
  • @Hilberto1 -What is the system of the computer you are using? Different computer systems have different ways to set python environment variables. For Windows, you could refer to the content of this link: [How do I add Python to the Windows PATH?](https://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path) – Jill Cheng Mar 22 '21 at 02:16
  • I'm using macOS – Hilberto1 Mar 22 '21 at 11:41
  • @Hilberto1 -Please refer to this: [Add to python path mac os x.](https://stackoverflow.com/questions/3387695/add-to-python-path-mac-os-x) or search for a more specific tutorial. – Jill Cheng Mar 23 '21 at 02:17