[Boost-users] importing boost-python module in python on windows

1,251 views
Skip to first unread message

Seema Jaisinghani

unread,
Jun 11, 2009, 8:20:55 PM6/11/09
to Boost...@lists.boost.org

Hi,

 

I have created an extension boost python module for C++ class, successfully using Visual Studio 2009, and get a shared library(.dll) as output.

 

However I am having trouble importing this module in my python code. I have explicitly tried importing the dll as resource in an Eclipse PyDev project, and also set in windows PATH environment variable, the location for this dll. With the PATH set, I also tried import from the python shell, but no success.

Can someone describe what is the process to import boost_python_modules in python on windows.

 

Thanks,

Seema

 

 

Nat Goodspeed

unread,
Jun 12, 2009, 11:27:02 AM6/12/09
to boost...@lists.boost.org
Seema Jaisinghani wrote:

Change your shared library's filename extension from .dll to .pyd. As of
Python 2.5, the Python interpreter stopped accepting .dll as a valid
extension module filename:

http://www.python.org/doc/2.5.4/whatsnew/ports.html#SECTION0001510000000000000000

"Windows: .dll is no longer supported as a filename extension for
extension modules. .pyd is now the only filename extension that will be
searched for."
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Seema Jaisinghani

unread,
Jun 12, 2009, 1:57:50 PM6/12/09
to boost...@lists.boost.org
Thanks for the response. Simply changing the name of the extension .dll to .pyd does not help.

ImportError: DLL load failed: The specified module could not be found.

It is not a path problem, as another module in the same location can be imported correctly.

I am building the boost_extension_module in Visual Studio IDE. Is there a way to output a pyd directly, instead of dll?
What else is required to let Python know about boost_python libs?


Thanks.

Nat Goodspeed

unread,
Jun 15, 2009, 10:41:15 AM6/15/09
to boost...@lists.boost.org
Seema Jaisinghani wrote:

> Thanks for the response. Simply changing the name of the extension .dll to .pyd does not help.
>
> ImportError: DLL load failed: The specified module could not be found.
>
> It is not a path problem, as another module in the same location can be imported correctly.

That would have been my next suggestion. What's the full filename of the
other module? Is it a Python module or another extension module?

Does your extension module depend on any other .dlls (not Python
extensions)? Where are they stored?

In a previous product, we had to set both PYTHONPATH and PATH:
PYTHONPATH to direct the interpreter to our extension modules, PATH to
direct the OS to the DLLs on which our extension modules depended.

> I am building the boost_extension_module in Visual Studio IDE.
> Is there a way to output a pyd directly, instead of dll?

I'm sure there is, but I don't have a Windows machine handy just now.
Poke around in the project's Properties panes.

> What else is required to let Python know about boost_python libs?

That should be all.

The Python interpreter knows nothing about Boost.Python. The
Boost.Python library simply automates construction of the interface data
required for any Python extension module. The classic approach was to
hand-code it. If you were having trouble with that interface data, you'd
get an entirely different error message.

Seema Jaisinghani

unread,
Jun 19, 2009, 7:53:54 PM6/19/09
to boost...@lists.boost.org
Hi,

I found that it was a version mismatch problem. I was using Python 2.6 and boost 1.37. Even though the boost-python project compiled with python 2.6 and the module was created without any errors. When I used the module within python 2.6, it was looking for python25.dll

Rebuilding with 2.5 fixed the problem.

Thanks,
Seema

Reply all
Reply to author
Forward
0 new messages