我下载了 gammu 源文件。我的目标是能够在我的 python 程序中使用 gammu 模块。如何为 python-gammu 运行 setup.py 安装。每次尝试,我都会得到 p>
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 身份安装。
关于python - 如何在Python gammu中使用setup.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529379/