wiki:Python_SIP/Build_Install

Version 24 (modified by ming, 7 years ago) (diff)

--

Build and Installation

* IMPORTANT! :* Python module for PJSIP has been deprecated and although it may still be usable, the module, as well as this doc page, will no longer be maintained. For the replacement, please use PJSUA2 and Python SWIG binding as described here.

Getting the Modules

Currently we only distribute source codes and not binaries.

The Python modules source codes along with some samples are included in PJSIP distribution, in pjproject/pjsip-apps/src/python directory. No separate download is needed.


Building The Modules From the Source

Linux (and probably Unix in general)

Requirements

  1. The usual requirements to build PJSIP, e.g. make, gcc, and binutils.
  2. Python: this normally should have been installed on every Linux.
  3. Python development package, to build the C extension. This might be called python2-devel (e.g. on Fedora) or python2.7-dev (e.g. on Ubuntu).

Building the Module

Using Python build script:

  1. Build the PJSIP libraries first with the usual "./configure && make dep && make" commands.
  2. Go to pjsip-apps/src/python directory.
  3. Run 'sudo python ./setup.py install' or just 'sudo make'

Sample session:

  
   $ cd your-pjsip-root-dir
   $ ./configure && make dep && make
   $ cd pjsip-apps/src/python
   $ sudo make

MacOS X

Requirements

We tested this on MacOS X 10.5.3 (Leopard), using the built-in Python installation. There don't seem to be any specific requirements (except the usual gcc, make, and binutils, which should have been installed by default).

Building the Module

The build instructions should be similar to the Linux instructions. Open Terminal from Application/Utilities/Terminal, and run this:

  
   $ cd your-pjsip-root-dir
   $ ./configure && make dep && make
   $ cd pjsip-apps/src/python
   $ sudo make

Note that depending on Python installation, Python extension setup mechanism will link the library using some default architectures, e.g: ppc, i386, and/or x86_64, which may contain different architectures to the library's so it may raise warning message:

  ld: warning: ignoring file ..., file was built for archive which is not the architecture being linked (...)

To avoid such warning, specify the architecture(s) to be linked via environment variable ARCHFLAGS before invoking make, e.g:

   $ export ARCHFLAGS="-arch x86_64"
   $ cd pjsip-apps/src/python
   $ sudo make

Microsoft Windows with Visual Studio

Requirements

  1. The usual PJSIP requirements for Windows, e.g. Visual Studio along with Platform SDK and DirectX SDK.
  2. Python SDK: I personally use ActivePython-2.4.3-12 distribution from ActiveState, since it has a matching debug package.
  3. Optional: debug package: the debug package is useful if you want to debug the C extension. You can download it from ftp://ftp.activestate.com/ActivePython/etc/

Visual Studio Setup

  1. Add Python include directory (e.g. C:\Python24\include) to Visual Studio include directories.
  2. Add Python library directory (e.g. C:\Python24\libs) to Visual Studio library directories.

Building the Modules

Step 1: Building the C Extension

Visual Studio 6:

  1. Open pjsip-apps.dsw from pjsip-apps\build directory.
  2. Select python_pjsua project as the active project.
  3. Build the project
  4. The _pjsua.pyd Python module will be placed in pjsip-apps\lib directory.
    • or in case of debug, it will be _pjsua_d.pyd

Visual Studio 2005:

  1. Open pjproject-vs8.sln from the PJSIP distribution directory.
  2. Select either Debug or Release from the build configuration
    • Note: the Python module does not support other build configurations.
  3. In Visual Studio, right click python_pjsua project from the Solution Explorer panel, and select Build from the pop-up menu.
    • Note: the python_pjsua project is not built by default if you build the solution, hence it needs to be built manually by right-clicking and select Build from the pop-up menu.
  4. The _pjsua.pyd Python module will be placed in pjsip-apps\lib directory.
    • or in case of debug, it will be _pjsua_d.pyd

Step 2: Installing the Modules:

  1. Open Command Prompt
  2. Go to pjsip-apps\src\python directory
  3. Run python setup-vc.py install (note that the installation script is setup-vc.py and not setup.py).

Sample session:

 C:> cd your-pjsip-root-directory
 C:> cd pjsip-apps\src\python
 C:> python setup-vc.py install
running install
running build
running build_py
running install_lib
running install_data
copying ..\..\lib\_pjsua.pyd -> c:\python24\lib\site-packages

Microsoft Windows with MinGW

I did not try this myself since I use Visual Studio, but Adamczak Krzysztof suggested this on PJSIP mailing list to build the extensions with MinGW:

 python setup.py build_ext --compiler=mingw32 install

Common Problems

Cannot open include file: 'Python.h'

You need to install Python SDK.

Testing the installation

To test the installation, simply run python and import pjsua module.

On Linux/Unix/MacOS X:

$ python
> import pjsua
> ^Z

$

Similarly on Windows:

C:> python
> import pjsua
> ^Z

C:>