How to get an example of using boost.python to communicate with Python3?

I want to use boost.pythonwith python 3.2+(preferably 3.4) and Visual Studio 2010.

When I try to make an example libs\python\example\tutorialagainst any Python3 (I tested 3.0, 3.2 and 3.4), it does not reference (see below). When I associate it with 2.7, it works.

The only change I make between attempts is an update user-config.jamin my home directory.

Therefore, it works when user-config.jam:

#  MSVC configuration
using msvc : 10.0 ;
# Python configuration:
using python : 2.7 : C:\\Python27 : C:\\Python27\\include : C:\\Python27\\libs ;

When I run bjam, I get:

C:\Boost\boost_1_55_0\libs\python\example\tutorial>bjam
link.jam: No such file or directory
...patience...
...patience...
...found 1678 targets...
...updating 8 targets...
compile-c-c++ bin\msvc-10.0\debug\hello.obj
hello.cpp
msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd
   Creating library bin\msvc-10.0\debug\hello_ext.lib and object bin\msvc-10.0\debug\hello_ext.exp
   msvc.manifest.dll bin\msvc-10.0\debug\hello_ext.pyd
   common.copy boost_python-vc100-gd-1_55.dll
   ..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_55.dll
           1 file(s) copied.
common.copy hello_ext.pyd
bin\msvc-10.0\debug\hello_ext.pyd
           1 file(s) copied.
capture-output bin\hello.test\msvc-10.0\debug\hello
           1 file(s) copied.
**passed** bin\hello.test\msvc-10.0\debug\hello.test
...updated 8 targets...

If I change user-config.jamto:

#  MSVC configuration
using msvc : 10.0 ;
# Python configuration:
using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs ;

and bjam clean, and then bjamwe get:

C:\Boost\boost_1_55_0\libs\python\example\tutorial>bjam
link.jam: No such file or directory
...patience...
...patience...
...found 1685 targets...
...updating 9 targets...
compile-c-c++ bin\msvc-10.0\debug\hello.obj
hello.cpp
msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd
   Creating library bin\msvc-10.0\debug\hello_ext.lib and object bin\msvc-10.0\debug\hello_ext.exp
   hello.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct _object * __cdecl boost::python::detail::init_module(struct PyModuleDef &,void (__cdecl*)(void))" (__imp_?init_module@detail@python@boost@@YAPAU_object@@AAUPyModuleDef@@P6AXXZ@Z) referenced in function _PyInit_hello_ext
   bin\msvc-10.0\debug\hello_ext.pyd : fatal error LNK1120: 1 unresolved externals

           call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
link /NOLOGO /INCREMENTAL:NO /DLL /DEBUG /MACHINE:X86 /MANIFEST /subsystem:console /out:"bin\msvc-10.0\debug\hello_ext.pyd" /IMPLIB:"bin\msvc-10.0\debug\hello_ext.lib" /LIBPATH:"C:\Python34\libs"   @"bin\msvc-10.0\debug\hello_ext.pyd.rsp"
           if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

...failed msvc.link.dll bin\msvc-10.0\debug\hello_ext.pyd bin\msvc-10.0\debug\hello_ext.lib bin\msvc-10.0\debug\hello_ext.pdb bin\msvc-10.0\debug\hello_ext.pdb...
...removing bin\msvc-10.0\debug\hello_ext.lib
...removing bin\msvc-10.0\debug\hello_ext.pdb
common.copy boost_python-vc100-gd-1_55.dll
..\..\..\..\bin.v2\libs\python\build\msvc-10.0\debug\boost_python-vc100-gd-1_55.dll
           1 file(s) copied.
...skipped <p.>hello_ext.pyd for lack of <pbin\msvc-10.0\debug>hello_ext.pyd...
...failed updating 3 targets...
...skipped 1 target...
...updated 2 targets...

While searching online, I find a couple of links to this error, but no solutions ... Here is the best link:

http://lists.boost.org/boost-build/2011/06/25147.php

, Python3 boost.python, - ... - boost Python 3?

/

+4
1

, , .

boost Python27 Python34 , , ( 7zip) ( Visual Studio 2010 ):

  • , user-config.jam :

    #  MSVC configuration
    using msvc : 10.0 ;
    # Python configuration:
    using python : 3.4 : C:\\Python34 : C:\\Python34\\include : C:\\Python34\\libs ;
    
  • cd C:\Boost\boost_1_55_0

  • bootstrap
  • b2 toolset=msvc-10.0 --build-type=complete --with-python --libdir=C:\Boost\lib\i386 install
  • cd C:\Boost\boost_1_55_0\libs\python\example\tutorial
  • set lib=c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB;c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib;C:\Boost\lib\i386;C:\Python34\libs ( Boost Lib )
  • bjam
  • hello.py att () :

    import hello_ext
    print(hello_ext.greet())
    
  • python hello.py prints hello, world ( , python - python 3.4.1 )

, , boost / python . , Python3, .

, , , , , 2.7. , - !

+3

Source: https://habr.com/ru/post/1545281/


All Articles