Zane470
Posts: 1
Joined: Thu Jul 28, 2016 4:47 pm

PiCamera script runs from IDE but not from terminal

Thu Jul 28, 2016 4:53 pm

So I have a simple PiCamera script that basically just calls the start_preview() function, and it works perfectly in the python 2.7.9 IDE if I click Run->Run Module.

When I call this script (named camera.py) from the terminal using:

python camera.py

It runs and executes successfully, but nothing happens. No camera preview window pops up...What is going on?

wmsrite
Posts: 5
Joined: Sat Jul 23, 2016 7:08 pm

Re: PiCamera script runs from IDE but not from terminal

Fri Jul 29, 2016 12:26 am

Have you enabled the camera in raspi-config?
Go to the terminal and from the command line type:

Code: Select all

raspi-config
It'll open a window interface. Make sure the camera is enabled and that I2C is also enabled. Both must be enabled to get the camera working. You might also want to enable SSH at the same time, you'll need it later. Then reboot.

After it reboots open the terminal again and type:

Code: Select all

raspistill -d
It should give you a 10 second or so preview. if That doesn't work check back and I'll help some more.
Best of luck,
Wm

beckerc
Posts: 1
Joined: Mon Feb 05, 2018 9:19 pm
Location: United States
Contact: Twitter

Re: PiCamera script runs from IDE but not from terminal

Fri May 04, 2018 3:06 am

Did you ever figure this out? I'm having the same problem and have tried everything I can think of to make this work from the command line. It seems very odd because I run other python programs from the same directory with no problem. Things I have tried that have not worked, mostly from online suggestions:

1. including a shebang line in the program
2. turning on I2C
3. going from headless to connecting with a screen

Again, the program works fine from an IDE and when I type individual lines into a python REPL, but fails when I type "python camera.py" in the LXTerminal when I am in the same directory as the program. (python3 camera.py also fails.) There are no error messages, but nothing happens. The next line of the command prompt is returned.

Here are the 3 lines of code of the program.

import picamera
camera = picamera.PiCamera()
camera.start_preview()

Any suggestions would be greatly appreciated as I am out of ideas.

mkond
Posts: 1
Joined: Fri Aug 03, 2018 4:34 pm

Re: PiCamera script runs from IDE but not from terminal

Fri Aug 03, 2018 4:48 pm

I have the same exact problem.
The following code run from the IDLE but not from a command line.

from picamera import PiCamera
from time import sleep
camera=PICamera()
camera.start_preview()
sleep(10)
camera.stop_preview()

If i run this code from the IDLE it works.
If I try to run it from a command line , (sudo python3 IR camera.py) it just returns the command prompt.
Any ideas?

kmob
Posts: 1
Joined: Sun Jan 20, 2019 6:05 am

Re: PiCamera script runs from IDE but not from terminal

Sun Jan 20, 2019 6:07 am

Try putting "camera.close()" at the end of the script

pcmanbob
Posts: 9465
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: PiCamera script runs from IDE but not from terminal

Tue Jan 22, 2019 1:45 pm

If i run this code from the IDLE it works.
If I try to run it from a command line , (sudo python3 IR camera.py) it just returns the command prompt.
Try changing the name of the saved file from IR camera.py to IRcamera.py

then call it with sudo python3 IRcamera.py are you sure you need to use sudo ?

Linux does not like spaces in file names.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: PiCamera script runs from IDE but not from terminal

Wed Jan 23, 2019 12:34 am

Why does that need sudo? Have you caught a nasty dose of sudoitis?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

John145
Posts: 1
Joined: Fri Feb 08, 2019 6:57 am

Re: PiCamera script runs from IDE but not from terminal

Wed Feb 13, 2019 7:15 am

Try using camera.close()n method or else try changing ur file name...That is only mybkexperience issue i see.

Return to “Python”