[英]Ruby gem not loading in stand-alone ruby script
我正在嘗試創建一個簡單的ruby應用程序以與Arduino一起使用。 我的問題是找不到Ruby Gems。 這是我的腳本代碼-來自我發現的一個教程:
#!/usr/bin/ruby -rubygems
require 'rubygems'
require 'serialport'
require 'gmail'
#plug in your username and password here
gmail = Gmail.connect("username", "password")
#count the number of unread messages
prev_unread = gmail.inbox.count(:unread)
#this *will* be different for you
#You need to find out what port your arduino is on
#and also what the corresponding file is on /dev
#You can do this by looking at the bottom right of the Arduino
#environment which tells you what the path.
port_file = '/dev/tty.usbmodem1421'
#this must be same as the baud rate set on the Arduino
#with Serial.begin
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
#create a SerialPort object using each of the bits of information
port = SerialPort.new(port_file, baud_rate, data_bits, stop_bits, parity)
wait_time = 4
#for an infinite amount of time
loop do
#get the number of unread messages in the inbox
unread = gmail.inbox.count(:unread)
#lets us know that we've checked the unread messages
puts "Checked unread."
#check if the number of unread messages has increased
#if so, we have a new email! So, blink the LED.
if unread > prev_unread
port.write "b"
end
#reset the number of unread emails
prev_unread = unread
#wait before we make another request to the Gmail servers
sleep wait_time
end
然后,我轉到該文件(gmail_notifier.rb)所在的目錄並運行ruby gmail_notifier.rb
。 這是運行該命令后收到的錯誤:
/Users/ryan/.rvm/rubies/ruby-2.0.0-head/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- serialport (LoadError)
from /Users/ryan/.rvm/rubies/ruby-2.0.0-head/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
from gmail_notifier.rb:4:in `<main>'
有人知道為什么找不到寶石嗎? 我確實已經運行了gem install gmail
和gem install serialport
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.