python - 如何在Python gammu中使用setup.py

标签 python gammu

我下载了 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 身份安装。

关于python - 如何在Python gammu中使用setup.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529379/

相关文章:

python - gammu 恢复期间检测到缓冲区溢出

c# - 如何使用C#在gammu中发送超过160个字符的消息

linux - 为什么 gammu 需要 sudo 才能工作?

python - 在 Mac 上将 Django 安装到 Python 3.3

python - 如何在不设置索引的情况下旋转数据框?

python - 根据多个条件乘以 pandas 列

mysql - 由于 SQL 语法错误,Gammu 无法启动服务

linux - Gammu runonreceive 不传递变量

python 带。无法去除换行符,但使用 f.read()

python - Tensorflow-两个二维张量的笛卡尔积