###前提・実現したいこと
Raspberry pi で、Pythonを使って天気予報を読み上げるプログラムを作成しています。
シェルスクリプトを完成させて、いざターミナルでスクリプトを実行させようとしたところ、以下のエラーメッセージが出て実行できませんでした。。
###発生している問題・エラーメッセージ
Traceback (most recent call last); File "talk_weather.py", line 67, in <module> main() File "talk_weather.py", line 15, in main say_datetime() File "talk_weather.py", line 24, in say_datetime proc = sibprocess.Popen(shlex.split(text)) File "/usr/lib/python2.7/subprocess.py", line 710, in__init__ errread,errwrite) File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Error 2] No such file or directory
###該当のソースコード
Python
1#!/usr/bin/env python 2# -*- coding:utf-8 -*- 3import shlex 4import subprocess 5from datetime import datetime 6import urllib2 7import json 8CMD_SAY = 'jsay' 9def main(): 10 say_datetime() 11 say_weather() 12 return 13def say_datetime(): 14 d = datetime.now() 15 text = '%s月%s日、%s時%s分%s秒' % (d.month, d.day, d.hour, d.minute, d.second) 16 text = CMD_SAY + ' ' + text 17 print text 18 proc = subprocess.Popen(shlex.split(text)) 19 proc.communicate() 20 return 21def say_weather(): 22 city = '130010'; # Tokyo 他の地域の方は、番号を変えてください。 23 json_url = 'http://weather.livedoor.com/forecast/webservice/json/v1' #API URL 24 weather_text = u'%sの天気は%sです。' 25 temperature_text = u'%sの予想最高気温、%s度、予想最低気温、%s度です。' 26 try: 27 r = urllib2.urlopen('%s?city=%s' % (json_url, city) ) 28 obj = json.loads( unicode(r.read()) ) 29 title = obj['title'] 30 forecasts = obj['forecasts'] 31 # TODAY 32 cast = forecasts[0] 33 temperature = cast['temperature'] 34 today_w_txt = weather_text % (cast['dateLabel'], cast['telop']) 35 today_t_txt = temperature_text % (cast['dateLabel'], temperature['max']['celsius'], temperature['min']['celsius']) 36 # TOMMOROW 37 cast = forecasts[1] 38 temperature = cast['temperature'] 39 tommorow_w_txt = weather_text % (cast['dateLabel'], cast['telop']) 40 # SAY 41 weather_str = title + ' ' + today_w_txt + ' ' + today_t_txt + ' ' + tommorow_w_txt 42 weather_str = weather_str.encode('utf-8') 43 text = '''%s '%s' ''' % (CMD_SAY, weather_str) 44 print text 45 proc = subprocess.Popen(shlex.split(text)) 46 proc.communicate() 47 finally: 48 r.close() 49 return 50### Execute 51if __name__ == "__main__": 52 main()
###試したこと
下記のサイトを参考に自分で手入力によりtalk_weather.pyを作成しましたが、ダメでしたので、下記サイトの管理人の方がサーバーにあげているファイルをwgetしましたが、それでも同じエラーメッセージが出て失敗しました。
Linuxでは改行コードに気を配らなければならない点をネットで知りましたが、サイト管理人の方のファイルは改行コードに問題はないのではと考えたので、他に問題があるのではと思っております。
"/usr/lib/python2.7/subprocess.py"にファイルがないとあるので、usr/lib/python2.7の中にsubprocess.pyがないので怒られているのかと思いましたが、きちんと存在していたので、何がエラーの原因か全くわからない状態です。
###補足情報(言語/FW/ツール等のバージョンなど)
Raspberry piもプログラミングも初心者のため、以下のサイトを参考にさせていただいています。
http://raspi.seesaa.net/article/415530289.html
このサイトでいう、talk_weather.pyが完成し、python talk_weather.pyを実行しようとした際に上記のエラーが出ている状態です。
Raspberry piはPi2 Model Bです。
Open Jtalkとhts_engineはインストール済みで、指定した言葉を話してくれるところまでは昨日出来ました。
昨日Raspberry piを使い始めたばかりでして、こちらで質問するのも初めてです。表現など足りない点があるかもしれませんが、アドバイスをいただけると幸いです。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/08 14:21