4

I try to compile PJSUA2 for Python. I could manage to compile the source with Visual Studio 2015 Community edition.

My question is, how can I install the Python module now?

The guide suggests to use make and make install. I tried to install also minwg, but it is not working as the project was compiled with VS.

I have also tried to compile with minwg, but I never could succeed due to undefined requirements. Also official PJSUA guide recommend to use VS for Windows.

Following settings have been applied to build from source:

  • Swig location has been added to path
  • JAVA_home system variable has been added
  • Java location has been added to path
  • Empty pjlib/include/pj/config_site.h has been created
  • Opened source in VS 2015 Community (all suggested VS package and module has been installed)
  • Set following project to do not compile:
    • pjsua_cli_uwp_comp
    • pjsua_cli_wp8
    • pjsua_cli_wp8_comp
  • Set swig_java_pjsua2 to build.
  • Add following folders to swig_java_pjsua2 VC++ include directories
    • c:\Program Files\Java\jdk-11.0.2\include
    • c:\Program Files\Java\jdk-11.0.2\include\win32
  • Build solution

2 Answers 2

2

I could make a workaround to compile pjsua2 for Python 3.7. If you have a better solution or just suggestion to this workaround, let me know

Preconditions:

  • List item
  • Download and extract swig (swigwin 4.0.0)
  • Download and install JDK
  • Download and install Python (Python 3.7.3 x64) and set at custom installation:
    • tick "Add Python to environment variables"
    • tick "Precompile standard library"
    • tick "Download debugging symbols"
    • tick "Download debug binaries (requires VS 2015 or later)"
    • set custom path if you want
    • add swigwin location to system path
    • add Python location to system path
    • add JAVA_HOME system variable
    • add %JAVA_HOME%\bin to system path
    • Install Visual Studio 2015 Community edition

Steps:

  • Download and extract pjsip 2.8
  • Create empty config_site.h under pjlib/inlclude/pj/ folder
  • Open pjproject-vs14.sln in VS
  • There will be an unsupported warning window, press OK
  • At the "Install Missing Features" windows, press install
  • VS installer will be started, and VS has to be closed to complete installation.
  • I have also added "Windows 10 SDK (10.0.10586)" to the installation.
  • I have also enabled developer mode on my Windows 10, but this could be optional
  • Open project again in VS
  • Set project to Release and x64 on the top dropdown
  • Right click on the solution, and go to Configuration Properties> Configuration
  • Remove all uwp and wp8 related projects from selection, like pjsua_cli_uwp_comp, pjsua_cli_wp8_comp
  • press OK, and build solution
  • I have had 34 succeeded and 0 failed solution after build.
  • Add following lines to pjsua2.i in pjsip-apps/src/swig folder

    %inline %{
    pj_ssize_t new_pj_ssize_t(int s) {
       return (pj_ssize_t) s;
    }
    %}
    

    this extra inline swig function provides workaround for create recorder issue

  • Open a command line (powershell did not work for this)
  • go to pjsip-apps/src/swig/python
  • Execute following command:

    swig -I../../../../pjlib/include -I../../../../pjlib-util/include -I../../../../pjmedia/include -I../../../../pjsip/include -I../../../../pjnath/include -py3 -c++  -python -threads ../pjsua2.i
    
  • Add new "Empty Project" (Visual C++) to solution with swig_python_pjsua2 name

  • Add libpjproject and pjsua2_lib as reference to this new project
  • Right click on the Header Files>Add>Existing Item...
  • Add pjsip-apps\src\swig\pjsua2_wrapp.h
  • Add a "new filter" to the project with name "Generated Code"
  • Right click on "Generated code" and add new existing item.
  • Add pjsip-apps\src\swig\pjsua2_wrapp.cxx
  • Right click on the project and Linker>Input
  • Add "Ws2_32.Lib" to "Additional Dependencies"
  • Go to "VC++ Directories"
  • Add following folder to include path(I have used full path!):
    • c:\python37\include
    • pjnath\include
    • pjsip\include
    • pjmedia\include
    • pjlib-util\include
    • pjlib\include
  • Add following folder to Library Directories:
    • C:\Python36\libs
  • Set at General:
    • Target Name: _$(ProjectName)
    • Target Extension: .pyd
    • Configuration Type: Dynamic Library (.dll)
  • Go to properties of the solution, and select swig_python_pjsua2 to build
  • Right click on swig_python_pjsua2 and build
  • Build should complete successfully
  • You will need to file to use pjsua2 library in python.
  • pjsua.py located under pjsip-apps/src/swig/python
  • x64/Release/_swig_python_pjsua2.pyd (rename this to _pjsua2.pyd)
  • To test, copy those to file into a folder, start python from same folder and type:
    • import pjsua2
0

Thank You very much Krisz for this awesome work!


I just got it working for Python 2.7 / 32bit and some things are slightly different, so I will add them here:

Environment:

  • Windows 10
  • SWIG 4.0.1
  • PJSIP 2.9
  • Python 2.7.14 (32bit)
  • Visual Studio Express 2015 (V 14.0.25431.01 Update 3)

Whaddado:

  1. Important: Check if your Python-interpreter is really x64 or win32 like the following: start a python session and enter:

    import platform

    platform.architecture()

    If you have 32bit, consider this in your choice for target platform in VS.

  2. when you add this %inline%-Snippet to pjsip-apps/src/swig/pjsua2.i, add it at the end of the file!

  3. when starting the swig-command, omit the "-py3"-parameter, if you use Python 2.x

  4. there is a little typo in Krisz' description, at "pjsua.py located under pjsip-apps/src/swig/python" -> of course pjsua2.py is meant. Do not use the pjsua.py.

finally copy _pjsua2.lib and pjsua2.py into \Lib\site-packages\ and the _pjsua2.pyd into \DLLs\ to make them available everywhere.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.