Python-如何获取导入pjsua?不提供名为pjsu的模块

2024-04-29 08:16:44 发布

您现在位置:Python中文网/ 问答频道 /正文

如何获取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)

Tags: pygnuhomeincludelinuxlibdownloadscall
3条回答

setup.py试图通过动态链接pjsip的库来创建共享库,但是这些库没有提供global offsets table(GOT)(请检查链接以了解为什么需要这样做)。

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

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

./configure

好吧,我在网上找不到一个很好的指南,而且@jcm的建议对我很有帮助,所以我想我可以把这个贴在这里。

我有一个类似于操作的问题。在我的构建过程中,我会得到一个错误:

/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的编译器有一个导致它segfault的错误:

$ 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

我显然去晚会迟到了,但我无论如何都会回答,这样可以帮助别人。几个小时的汗流浃背之后,找到了这些安装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

相关问题 更多 >