«ImportError: нет модуля с именем omxplayer.player» при запуске скрипта Python из командной строки - PullRequest
0 голосов
/ 11 декабря 2018

Я написал простой скрипт для воспроизведения случайного видео при нажатии кнопки на Raspberry Pi.Он прекрасно работает со встроенной Raspberry Pi Python 3 IDE.Работает так, как должно

import RPi.GPIO as GPIO
import random
import os
import sys
from time import sleep
from subprocess import call
from omxplayer.player import OMXPlayer

#Uses the board pin number
GPIO.setmode(GPIO.BOARD)

#Delays
Skip_Wait_Time = 1
Genre_Wait_Time = 3
Next_Movie_Wait_Time= 4


#Pin Numbers
Button1_Pin = 35
Button2_Pin = 33
Button3_Pin = 23
Button4_Pin = 24

ShutdownButton_Pin = 21
QuitButton_pin = 37

#Sets Up the 4 GPIO Pins with pull ups
GPIO.setup(Button1_Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(Button2_Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(Button3_Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(Button4_Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(ShutdownButton_Pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(QuitButton_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Action
Genre1 = ("/home/pi/Videos/ActionMovies/")

#Comedy
Genre2 = ("/home/pi/Videos/ComedyMovies/")

#Sitcoms
Genre3 = ("/home/pi/Videos/Sitcoms/")

#Drama
Genre4 = ("/home/pi/Videos/DramaMovies/")

#Christmas
Genre5 = ("/home/pi/Videos/ChristmasMovies/")

#Button States
Button1_State = True
Button2_State = True
Button3_State = True
Button4_State = True

ShutdownButton_state = True
QuitButton_state = True

#variable
Current_Genre = "Genre1"
Current_Genre_Directory = "Null"
Current_Movie_Path = "Null"
episode= "Null"
Time_Remaining = 2
elapsed = 0
Button_Pressed = False




#-------------------------------------------
#---------------- MAIN LOOP ----------------
#-------------------------------------------
while Button_Pressed == False:

Button1_State = GPIO.input(Button1_Pin)
Button2_State = GPIO.input(Button2_Pin)
Button3_State = GPIO.input(Button3_Pin)
Button4_State = GPIO.input(Button4_Pin)

if Button1_State == False:
    Current_Genre = "Genre1"
    Button_Pressed = True
    Current_Genre_Directory = Genre1
if Button2_State == False:
    Current_Genre = "Genre2"
    Button_Pressed = True
    Current_Genre_Directory = Genre2
if Button3_State == False:
    Current_Genre = "Genre3"
    Button_Pressed = True
    Current_Genre_Directory = Genre3
if Button4_State == False:
    Current_Genre = "Genre4"
    Button_Pressed = True
    Current_Genre_Directory = Genre4

episode = random.choice(os.listdir(Current_Genre_Directory))
Current_Movie_Path = Current_Genre_Directory + episode
player = OMXPlayer(Current_Movie_Path)



while ShutdownButton_state == True and QuitButton_state == True:

Button_Pressed = False

elapsed = player.position()
Time_Remaining = (player.duration()  - elapsed)


#Reads the state of the buttons
Button1_State = GPIO.input(Button1_Pin)
Button2_State = GPIO.input(Button2_Pin)
Button3_State = GPIO.input(Button3_Pin)
Button4_State = GPIO.input(Button4_Pin)
ShutdownButton_state = GPIO.input(ShutdownButton_Pin)
QuitButton_state = GPIO.input(QuitButton_pin)


if Button1_State == False:
    Current_Genre = "Genre1"
    Button_Pressed = True
    Current_Genre_Directory = Genre1
if Button2_State == False:
    Current_Genre = "Genre2"
    Button_Pressed = True
    Current_Genre_Directory = Genre2
if Button3_State == False:
    Current_Genre = "Genre3"
    Button_Pressed = True
    Current_Genre_Directory = Genre3
if Button4_State == False:
    Current_Genre = "Genre4"
    Button_Pressed = True
    Current_Genre_Directory = Genre4




if Time_Remaining < 1.0 :
    episode = random.choice(os.listdir(Current_Genre_Directory))
    Current_Movie_Path = Current_Genre_Directory + episode
    player.load(Current_Movie_Path, pause=False)
    sleep(Next_Movie_Wait_Time)



if Button_Pressed == True:
    episode = random.choice(os.listdir(Current_Genre_Directory))
    Current_Movie_Path = Current_Genre_Directory + episode
    player.load(Current_Movie_Path, pause=False)
    sleep(Skip_Wait_Time)







#what happens if quit or shutdown are pressed
if QuitButton_state == False:
player.quit()
GPIO.cleanup()

if ShutdownButton_state == False:
call("sudo shutdown -h now", shell=True)

Моя проблема в том, что когда я запускаю программу через командную строку с:

sudo python3 /home/pi/RandomMoviePlayer_Rev1.py

Я получаю сообщение об ошибке:

"Traceback (most recent call last):
File "/home/pi/RandomMoviePlayer_Rev1.py", line 7, in <module>
from omxplayer.player import OMXPlayer
ImportError: No module named 'omxplayer'"

Я действительно не уверен, что делать, чтобы выяснить, что происходит.Я попытался установить OMXPLAYER с pip и pip3

Любая помощь будет принята с благодарностью

...