Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i use python libraries in C++?

Tags:

c++

python

nltk

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

like image 223
sundeep Avatar asked Nov 17 '08 22:11

sundeep


People also ask

Can you use Python libraries in C?

One of the lesser-known yet incredibly powerful features of Python is its ability to call functions and libraries defined in compiled languages such as C or C++.

Can I mix Python with C?

Extending Python with C or C++ It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can't be done directly in Python: they can implement new built-in object types, and they can call C library functions and system calls.

How does Python work with C?

Python code can make calls directly into C modules. Those C modules can be either generic C libraries or libraries built specifically to work with Python. Cython generates the second kind of module: C libraries that talk to Python's internals, and that can be bundled with existing Python code.

Can we use Python libraries in C++?

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


2 Answers

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.

like image 60
zdan Avatar answered Sep 21 '22 00:09

zdan


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.

like image 22
Martin Beckett Avatar answered Sep 18 '22 00:09

Martin Beckett