Python - 如何获取导入pjsua?没有给出名为pjsua的模块

时间:2013-11-25 14:27:07

标签: python linux pjsip

如何获取python pjsua?

$ wget http://www.pjsip.org/release/2.1/pjproject-2.1.tar.bz2
$ tar xvfj pjproject-2.1.tar.bz2
$ cd pjproject-2.1.0
$ ./configure 
$ make dep && make
$ make install
$ ldconfig
$ ldconfig -p | grep pj


$ cd ./pjsip-apps/src/python
$ python setup.py install
running install
running build
running build_py
running build_ext
building '_pjsua' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPJ_AUTOCONF=1 -I-DPJ_IS_BIG_ENDIAN=0 -I-DPJ_IS_LITTLE_ENDIAN=1 -I/home/sun/Downloads/pjproject-2.1.0/pjlib/include -I/home/sun/Downloads/pjproject-2.1.0/pjlib-util/include -I/home/sun/Downloads/pjproject-2.1.0/pjnath/include -I/home/sun/Downloads/pjproject-2.1.0/pjmedia/include -I/home/sun/Downloads/pjproject-2.1.0/pjsip/include -I/usr/include/python2.7 -c _pjsua.c -o build/temp.linux-x86_64-2.7/_pjsua.o
_pjsua.c: In function ‘py_pjsua_enum_transports’:
_pjsua.c:1201:17: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_conf_get_port_info’:
_pjsua.c:2337:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_get_snd_dev’:
_pjsua.c:2713:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_call_make_call’:
_pjsua.c:3139:7: warning: passing argument 3 of ‘pjsua_call_make_call’ makes pointer from integer without a cast [enabled by default]
In file included from _pjsua.h:27:0,
                 from _pjsua.c:20:
/home/sun/Downloads/pjproject-2.1.0/pjsip/include/pjsua-lib/pjsua.h:4234:22: note: expected ‘const struct pjsua_call_setting *’ but argument is of type ‘unsigned int’
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_pjsua.o -L/home/sun/Downloads/pjproject-2.1.0/pjlib/lib -L/home/sun/Downloads/pjproject-2.1.0/pjlib-util/lib -L/home/sun/Downloads/pjproject-2.1.0/pjnath/lib -L/home/sun/Downloads/pjproject-2.1.0/pjmedia/lib -L/home/sun/Downloads/pjproject-2.1.0/pjsip/lib -L/home/sun/Downloads/pjproject-2.1.0/third_party/lib -lpjsua-x86_64-unknown-linux-gnu -lpjsip-ua-x86_64-unknown-linux-gnu -lpjsip-simple-x86_64-unknown-linux-gnu -lpjsip-x86_64-unknown-linux-gnu -lpjmedia-codec-x86_64-unknown-linux-gnu -lpjmedia-videodev-x86_64-unknown-linux-gnu -lpjmedia-x86_64-unknown-linux-gnu -lpjmedia-audiodev-x86_64-unknown-linux-gnu -lpjnath-x86_64-unknown-linux-gnu -lpjlib-util-x86_64-unknown-linux-gnu -lresample-x86_64-unknown-linux-gnu -lmilenage-x86_64-unknown-linux-gnu -lsrtp-x86_64-unknown-linux-gnu -lgsmcodec-x86_64-unknown-linux-gnu -lspeex-x86_64-unknown-linux-gnu -lilbccodec-x86_64-unknown-linux-gnu -lg7221codec-x86_64-unknown-linux-gnu -lportaudio-x86_64-unknown-linux-gnu -lpj-x86_64-unknown-linux-gnu -lm -lnsl -lrt -lpthread -lcrypto -lssl -o build/lib.linux-x86_64-2.7/_pjsua.so
/usr/bin/ld: /home/sun/Downloads/pjproject-2.1.0/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a(pjsua_acc.o): relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/home/sun/Downloads/pjproject-2.1.0/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


$ python
Python 2.7.3 (default, Apr 10 2013, 05:13:16) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pjsua
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pjsua

修改

p2p | registration | call

$ python sip_hello.py sip:localhost:5080
18:22:21.607 os_core_unix.c !pjlib 2.1 for POSIX initialized
18:22:21.608 sip_endpoint.c  .Creating endpoint instance...
18:22:21.608          pjlib  .select() I/O Queue created (0x131b9f0)
18:22:21.608 sip_endpoint.c  .Module "mod-msg-print" registered
18:22:21.608 sip_transport.  .Transport manager created.
18:22:21.608   pjsua_core.c  .PJSUA state changed: NULL --> CREATED
18:22:21.622   pjsua_core.c  .pjsua version 2.1 for Linux-3.5.0.17/x86_64/glibc-2.15 initialized
18:22:21.625    pjsua_aud.c  ..Error retrieving default audio device parameters: Unable to find default audio device (PJMEDIA_EAUD_NODEFDEV) [status=420006]
Exception: Object: {Account <sip:192.168.1.15:57717>}, operation=make_call(), error=Unable to find default audio device (PJMEDIA_EAUD_NODEFDEV)

3 个答案:

答案 0 :(得分:8)

setup.py正在尝试通过动态链接pjsip的库来创建共享库build/lib.linux-x86_64-2.7/_pjsua.so,但是,这些库不提供global offsets table(GOT)(请查看链接以了解为何需要这样做)。

问题是./configure没有提供gcc的-fPIC选项,我建议创建一个configure-linux脚本,如:

#!/bin/sh
#
export CFLAGS="$CFLAGS -fPIC"

./configure

答案 1 :(得分:5)

好的,我无法在网上找到一个好的指南,@ jcm的建议帮助了我,所以我想我会在这里发布。

我对OP有类似的问题。在我的构建期间,我会收到错误:

/usr/bin/ld: /opt/pjproject-2.2.1/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a(pjsua_acc.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/opt/pjproject-2.2.1/pjsip/lib/libpjsua-x86_64-unknown-linux-gnu.a: could not read symbols: Bad value

添加标志不会修复它。

我不知道这有多少是不必要的,但这对我有用。请注意,您必须删除该文件夹并从头开始。这可能是“干净”的工作,但删除和重建对我来说最简单:

sudo apt-get install build-essential python-dev
sudo rm -fr pjproject-2.2.1
tar -xf pjproject-2.2.1.tar.bz2 && cd pjproject-2.2.1/
export CFLAGS="$CFLAGS -fPIC"
./configure && make dep && make
cd pjsip-apps/src/python/
sudo python setup.py install

我还应该注意到我在虚拟机(ubuntu 14.04)中这样做了,因为(据我所知)Ubuntu 12.04的编译器有一个导致它出现段错误的错误:

$ sudo python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying pjsua.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_pjsua' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPJ_AUTOCONF=1 -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjlib/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjlib-util/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjnath/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjmedia/include -I/home/isaac_witmer/Downloads/pjproject-2.2.1/pjsip/include -I/usr/include/python2.7 -c _pjsua.c -o build/temp.linux-x86_64-2.7/_pjsua.o
_pjsua.c: In function ‘py_pjsua_enum_transports’:
_pjsua.c:1202:17: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_conf_get_port_info’:
_pjsua.c:2338:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
_pjsua.c: In function ‘py_pjsua_get_snd_dev’:
_pjsua.c:2714:9: warning: variable ‘status’ set but not used [-Wunused-but-set-variable]
In file included from _pjsua.c:20:0:
_pjsua.h: In function ‘PyObj_pjsip_cred_info_delete’:
_pjsua.h:71:13: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccDoI9J3.out file, please attach this to your bugreport.
error: command 'gcc' failed with exit status 1

答案 2 :(得分:2)

我显然已经迟到了,但无论如何我都在回答,所以它可以帮助别人。经过几个小时的出汗,发现这些简单的步骤来安装pjsua。这些命令还会为您安装所有依赖项。我在UBUNTU上使用过它,不确定它是否适用于其他地方。为此,您需要卸载并删除任何现有的pjsua软件包。

sudo apt-get install -y software-properties-common # To make add-apt-repository work
sudo add-apt-repository ppa:dennis.guse/sip-tools 
sudo apt-get update 
sudo apt-get install python-pjsua
sudo apt-get install python-pjsua2

检查一切是否顺利:

python
import pjsua 

不确定为什么官方页面没有这些可以节省大量时间的命令。我从here获得了此文档。

运行示例文件:

wget http://svn.pjsip.org/repos/pjproject/trunk/pjsip-apps/src/python/samples/simplecall.py
python simplecall.py sip:ipaddress:portnumber