3

I seem to be stuck with trying to run python3 files in vscode. I have noticed the Triangle button in the top right hand side to run code is no longer coloured green too.

I have set up my own venv for python3 and have installed the numpy package - I've checked pip list and it's there and runs fine when called any methods from this package upon importing it.

When i right click the file in vscode and click on Run Python File in Terminal - it runs perfectly fine and gives me the desired outputs.

However, when I click Run Code or Alt+shift+N it opens up the Output tab next to the terminal and produces no output - just an error message stating that the module numpy does not exist.

I do not understand this, since the numpy pacakge is installed. Can anyone try and help me with this - because it is quite tiring having the right click all the time and click "run python file in the terminal" i was hoping for a keyboard shortcut instead.

I've attached my code below

import numpy as np 
print(np.round(5/30,decimals=3))

Please see the following screen captures.

You can clearly see the output running correctly in when Python3 file is sent to the terminal - but in the OUTPUT tab it's an error!

Works in Terminal

The above is the correct result from the Terminal

Below is the result of the OUTPUT tab.

Fails when running in OUTPUT

2 Answers 2

2

Solved it myself - the answer was simply here:

How to execute Python code from within Visual Studio Code

I needed to change the path of the code-runner in the settings.json file as that was activated.

Sign up to request clarification or add additional context in comments.

Comments

0

To run your code when it says "ModuleNotFoundError":

Right-click, go down to run python file, and click on "run python file in terminal".

I was stuck on this for hours. Every source just told me I didn't have "module" installed which I clearly did.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.