picamera on raspberry pi zero module not installed - python-3.x

SUMMARY:
Unable to run a time-lapse Python3 script due to a module not being installed. I am running Raspian Lite on Raspberry Pi Zero W.
THINGS I'VE TRIED:
I've tried installing picamera module for python. Tried googling the error and came across https://raspberrypi.stackexchange.com/questions/88339/importerror-no-module-named-picamera
Here is a list of installed modules. I can't see picamera on there??
help('modules')
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer aifc httplib sets
Bastion antigravity ihooks sgmllib
CDROM anydbm imageop sha
CGIHTTPServer argparse imaplib shelve
Canvas array imghdr shlex
ConfigParser ast imp shutil
Cookie asynchat importlib signal
DLFCN asyncore imputil site
Dialog atexit inspect sitecustomize
DocXMLRPCServer audiodev io smtpd
FileDialog audioop itertools smtplib
FixTk base64 json sndhdr
HTMLParser bdb keyword socket
IN binascii lib2to3 spwd
MimeWriter binhex linecache sqlite3
Queue bisect linuxaudiodev sre
RPi bsddb locale sre_compile
ScrolledText bz2 logging sre_constants
SimpleDialog cPickle lsb_release sre_parse
SimpleHTTPServer cProfile macpath ssl
SimpleXMLRPCServer cStringIO macurl2path stat
SocketServer calendar mailbox statvfs
StringIO cgi mailcap string
TYPES cgitb markupbase stringold
Tix chunk marshal stringprep
Tkconstants cmath math strop
Tkdnd cmd md5 struct
Tkinter code mhlib subprocess
UserDict codecs mimetools sunau
UserList codeop mimetypes sunaudio
UserString collections mimify symbol
_LWPCookieJar colorsys mmap symtable
_MozillaCookieJar commands modulefinder sys
builtin compileall multifile sysconfig
future compiler multiprocessing syslog
_abcoll contextlib mutex tabnanny
_ast cookielib netrc tarfile
_bisect copy new telnetlib
_bsddb copy_reg nis tempfile
_codecs crypt nntplib termios
_codecs_cn csv ntpath test
_codecs_hk ctypes nturl2path textwrap
_codecs_iso2022 curses numbers this
_codecs_jp datetime opcode thread
_codecs_kr dbhash operator threading
_codecs_tw dbm optparse time
_collections decimal os timeit
_csv difflib os2emxpath tkColorChooser
_ctypes dircache ossaudiodev tkCommonDialog
_ctypes_test dis parser tkFileDialog
_curses distutils pdb tkFont
_curses_panel dl pickle tkMessageBox
_elementtree doctest pickletools tkSimpleDialog
_functools dumbdbm pipes toaiff
_hashlib dummy_thread pkgutil token
_heapq dummy_threading platform tokenize
_hotshot email plistlib trace
_io encodings popen2 traceback
_json ensurepip poplib ttk
_locale errno posix tty
_lsprof exceptions posixfile turtle
_md5 fcntl posixpath types
_multibytecodec filecmp pprint unicodedata
_multiprocessing fileinput profile unittest
_osx_support fnmatch pstats urllib
_pyio formatter pty urllib2
_random fpformat pwd urlparse
_sha fractions py_compile user
_sha256 ftplib pyclbr uu
_sha512 functools pydoc uuid
_socket future_builtins pydoc_data warnings
_sqlite3 gc pyexpat wave
_sre genericpath quopri weakref
_ssl getopt random webbrowser
_strptime getpass re whichdb
_struct gettext readline wsgiref
_symtable glob repr xdrlib
_sysconfigdata grp resource xml
_sysconfigdata_nd gzip rexec xmllib
_testcapi hashlib rfc822 xmlrpclib
_threading_local heapq rlcompleter xxsubtype
_warnings hmac robotparser zipfile
_weakref hotshot runpy zipimport
_weakrefset htmlentitydefs sched zlib
abc htmllib select
CODE BELOW:
from time import sleep
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
WAIT_TIME = 300
with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
for filename in
camera.capture_continuous('/home/pi/camera/img{timestamp:%H-%M-%S-%f}.jpg'):
sleep(WAIT_TIME)
The expected result is images to appear in the camera folder timestamped every 5 minutes.

While it is not stated in the documentation of picamera and it could be that its trying to run in python 2.
But I found the solution to be the following:
You need to have the following packages installed: python-picamera & python3-picamera
So running:
sudo apt-get install python-picamera fixed it

Related

Is there a way to use the ffmpeg binary/unix executable in a py2app application to run ffmpeg on computers without it installed?

I wrote a small python script that is essentially just a text to speech script. It uses the pydub - audiosegment python library to convert the mp3 from gTTS to an ogg that can be played in pygame. A link to my github repository can be found here: https://github.com/AnupPlays/TTS
this is the main function:
def webscrape():
global x
global b
b.state(['disabled'])
src = "sound.mp3"
dst = "sound.ogg"
murl = str(url.get())
response = requests.get(murl)
response.raise_for_status()
parse = bs4.BeautifulSoup(response.text, 'html.parser')
x = str(parse.get_text())
print(x)
text = gTTS(x)
text.save("sound.mp3")
AudioSegment.from_mp3(src).export(dst, format='ogg')
b.state(['!disabled'])
this is a list of my imports:
#Imports
import os
import sys
import pygame
#google text to speech
from gtts import gTTS
#requests and BeautifulSoup
import requests
import bs4
#pygame audio player
from pygame import mixer
#tkinter ui
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from tkinter import messagebox
#mp3 -> wav
from os import path
from pydub import AudioSegment
For anyone wondering using homebrew you can get the dependencies for this and copy those dependencies into your packager.

module 'subprocess' has no attribute '_subprocess'

I used python3.7 in windows7.
When I tried to run this line: suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
error occurs: module 'subprocess' has no attribute '_subprocess'
import os
import sqlite3
import subprocess
import time
import re
from django.core.mail import send_mail
from django.http import HttpResponse
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
How to deal with that?
There is no such thing as subprocess._subprocess, the constant is straight under subprocess:
suinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
See the docs: https://docs.python.org/3/library/subprocess.html#subprocess.STARTF_USESHOWWINDOW

How to convert audio file to picture for every 0.1 seconds in python

I have an auido file of the engine. I would like to convert it into the spectrogram.
import matplotlib.pyplot as plot
from scipy import signal
from scipy.io import wavfile
from pydub import AudioSegment
samplingFrequency, signalData = wavfile.read('datamusic/car2.wav')
plot.subplot(111)
plot.specgram(signalData,Fs=samplingFrequency)
plot.savefig("datapicture/car2.png")
It is the code that o have found. However it converts all sound.

JPype error: import jpype ModuleNotFoundError: No module named 'jpype'

I installed JPype in a correct way and anything is fine and my instalation was succeed but when i run my refactor.py from command prompt i have error that i pointed in title.
i hope you can help me for solving this problem.
also i have to point that i am beginner in python3.
here is my code:
import urllib.request
import os
import tempfile
import sys
import fileinput
import logging
import jpype
logging.basicConfig(filename="ERROR.txt", level= logging.ERROR)
try:
logging.debug('we are in the main try loop')
jpype.startJVM("C:/Users/user/AppData/Local/Programs/Python/Python36/ClassWithTest.java", "-ea")
test_class = jpype.JClass("ClassWithTest")
a = testAll()
file_java_class = open("OUTPUT.txt", "w")
file_java_class.write(a)
except Exception as e1:
logging.error(str(e1))
jpype.shutdownJVM()
startJVM() function takes the path to the JVM which is like this - C:\\Program Files\\Java\\jdk-10.0.2\\bin\\server\\jvm.dll. You could use the getDefaultJVMPath() function to get the JVM path on your PC. So you can just start the JVM this way:
startJVM(getDefaultJVMPath(), "-ea")
Hope that helps!

Python Sumy - no module named: sumy.parsers.html

I started using Sumy, a paragraph summariser for Python. I run their sample code but it gives me this error:
from sumy.parsers.html import HtmlParser
ImportError: No module named sumy.parsers.html
I'm on the right version so it should work?
Sample code that I used from their website:
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
from sumy.parsers.html import HtmlParser
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lsa import LsaSummarizer as Summarizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
LANGUAGE = "czech"
SENTENCES_COUNT = 10
if __name__ == "__main__":
url = "http://www.zsstritezuct.estranky.cz/clanky/predmety/cteni/jak-naucit-dite-spravne-cist.html"
parser = HtmlParser.from_url(url, Tokenizer(LANGUAGE))
# or for plain text files
# parser = PlaintextParser.from_file("document.txt", Tokenizer(LANGUAGE))
stemmer = Stemmer(LANGUAGE)
summarizer = Summarizer(stemmer)
summarizer.stop_words = get_stop_words(LANGUAGE)
for sentence in summarizer(parser.document, SENTENCES_COUNT):
print(sentence)
It won't work if your filename is named with 'sumy'. Check that. Also check the python version for which sumy is installed and then run it.

Resources