如何在Python gammu中使用setup.py

5 投票
1 回答
1581 浏览
提问于 2025-04-18 11:51

我下载了gammu的源代码文件。我的目标是能够在我的Python程序中使用gammu模块。请问我该怎么运行setup.py来安装python-gammu呢?每次我尝试的时候,都会出现

running install
running build
running build_py
running build_ext
ERROR: Could not find pkg-config!

1 个回答

0

首先,你需要安装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在系统上是以非管理员身份安装的。

撰写回答