C ++ encapsulate the python extension module ImportError

Source: Internet
Author: User

Compile the extension module (Dynamic Link Library) for Python using C ++ and call the extension function developed by C ++ in Python. the following error occurs, is it annoying:
Traceback (most recent calllast ):

File "t. py", line 6, in <module>

Import Rabbit

ImportError: No modulenamed Rabbit

Possible causes include:

1. If Python2.5 is used during development, check whether the generated dynamic library extension is "pyd". (If the suffix is dll, modify it );

2. In the source code of DLLMAIN, export the initialization code of the extension module:

# Ifdef PYRABBIT_EXPORTS

# Define PYRABBIT_API _ declspec (dllexport)

# Else

# DefinePYRABBIT _ declspec (dllimport)

# Endif

Extern "C" PYRABBIT_API void initRabbit (){

PyObject * m = Py_InitModule ("Rabbit", RabbitMethods );

}

3. The generated dynamic library file (suffixed with pyd) is not included in the environment variable. You can run the following command on the console to check the file;

Import OS

OS. sys. path

 

From bored blogs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.