简体   繁体   中英

how do i use python libraries in C++?

I want to use the nltk libraries in c++.

Is there a glue language/mechanism I can use to do this?

Reason: I havent done any serious programming in c++ for a while and want to revise NLP concepts at the same time.

Thanks

Although calling c++ libs from python is more normal - you can call a python module from c++ by bascially calling the python intepreter and have it execute the python source. This is called embedding

Alternatively the boost.python library makes it very easy.

You can also try the Boost.Python library; which has this capability . This library is mainly used to expose C++ to Python, but can be used the other way around.

I haven't tried directly calling Python functions from C++, but here are some alternative ideas...

Generally, it's easier to call C++ code from a high-level language like Python than the other way around. If you're interested in this approach, then you could create a C++ codebase and access it from Python. You could either directly use the external API provided by python [it should be described somewhere in the Python docs] or use a tool like SWIG to automate the C++-to-Python wrapping process.

Depending on how you want to use the library, you could alternatively create Python scripts which you call from C++ with the exec* functions.

Pyrex can be cleanly used for this purpose. There's an example in the source-code release.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM