Get Python Version using C++

Get Python Version using C++

Python is a versatile and popular programming language, which is used in various areas like web development, data science, artificial intelligence, and more. If you're working with C++ and need to interact with Python, it's essential to know the Python version installed on the system. This tutorial explains how to get Python version using C++.

In the given code snippet, we capture a string containing Python version information and assign it to a variable. Afterward, the retrieved version is displayed on the console.

#include <Python.h> #include <iostream> int main() { std::string version = PY_VERSION; std::cout << version << std::endl; return 0; }

The version adheres to the major.minor.revision format. Here is an example of the output:

3.11.7

Leave a Comment

Cancel reply

Your email address will not be published.