我下载了 gammu 源文件。我的目标是能够在我的 python 程序中使用 gammu 模块。如何运行 python-gammu 的 setup.py 安装。每次我尝试,我都会得到
running install
running build
running build_py
running build_ext
ERROR: Could not find pkg-config!
您首先需要安装 PIP,如果您使用的是 linux,则安装 python-gammu 比在其他操作系统上使用要好得多。
图书馆很简单。
#!/usr/bin/env python
# Sample script to show how to send SMS
import gammu
import sys
# Create object for talking with phone
sm = gammu.StateMachine()
# Optionally load config file as defined by first parameter
if len(sys.argv) >= 2:
# Read the configuration from given file
sm.ReadConfig(Filename = sys.argv[1])
# Remove file name from args list
del sys.argv[1]
else:
# Read the configuration (~/.gammurc)
sm.ReadConfig()
# Check parameters
if len(sys.argv) != 2:
print 'Usage: sendsms.py [configfile] RECIPIENT_NUMBER'
sys.exit(1)
# Connect to the phone
sm.Init()
# Prepare message data
# We tell that we want to use first SMSC number stored in phone
message = {
'Text': 'python-gammu testing message',
'SMSC': {'Location': 1},
'Number': sys.argv[1],
}
# Actually send the message
sm.SendSMS(message)
这里是更多信息的链接。 http://wammu.eu/docs/manual/python/examples.html
请记住,您可以使用控制台毫无问题地执行此操作……您必须记住的唯一一件事是在发送消息之前应用 sudo 命令,因为 gammu 在系统上以非 root 身份安装。