Python – 如何获得导入pjsua? 不给模块命名pjsua

如何获得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 | 注册 | 呼叫

 $ 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) 

setup.py尝试通过动态链接build/lib.linux-x86_64-2.7/_pjsua.so库来创建共享库build/lib.linux-x86_64-2.7/_pjsua.so ,但是这些库不提供全局偏移表(GOT) (查看链接以了解为什么是这样是需要的)。

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

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

好的,我无法在网上找到一个好的指南,@ 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 

我显然迟到了,但我仍然在回答,所以可以帮助别人。 出汗后数小时发现这些简单的步骤来安装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 

不知道为什么官方网页没有这些可以节省很多时间的命令。 我从这里得到这个文件。

运行示例文件:

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