0

I'm running a Python3 program to record a small video on a Raspberry Pi 4B:

` import time

from picamera2 import Picamera2
from picamera2.encoders import H264Encoder

picam2 = Picamera2()
video_config = picam2.create_video_configuration()
picam2.configure(video_config)

encoder = H264Encoder(10000000)
picam2.start_recording(encoder,'/home/pi/test.h264')
 time.sleep(10)
picam2.stop_recording()`

When I run this program in VS_Code I receive an error message "no module named picamera2". When I run the same program in Thonny it records a video. Executing import picamera2 in the terminal works also. I like working in VS_Code. Does anyone have an idea why it is reporting an error? Thanks, Jim.

jimk572
  • 1
  • 1
  • Have you tried [reloading](https://stackoverflow.com/a/42002990/11286032) your vscode window? – Marcelo Paco Mar 09 '23 at 06:09
  • 1
    Do they all use the same Python installation and there’s no virtual environments in play? VS Code should show a selection of Python version, check that it’s the correct one if you happen to have multiple – Sami Kuhmonen Mar 09 '23 at 06:09

1 Answers1

1

If you are pressing the run button on the vscode then the appropriate python interpreter should be pointed. if you are running in terminal u know for which interpreter u have installed all the libraries.

To get this solved u just have to choose the right interpreter in the vs code:

you can follow the below step if u have created a venv and using it:

step 1: click on the python version displayed on the right botton corner of your vscode.

step2: select the enter interpreter path if you want to specify manual alternate path of the python interpreter if you are not using venv.

interpreter

step2 : alternative if you are using a venv click as shown below , vs code automatically picks the right version for you.

venv selection

Surya R
  • 445
  • 2
  • 10