3,970 questions
Visual Studio cant find my python file.
Bratcher, Howard
1
Reputation point
I am trying to link python and C++ in visual studio. I am hopefully in the right place, maybe I am not using the right words because I cant find an article on this exact subject anywhere. It seems like I can't get my compiler to find my file (in C++) that contains the python code it is supposed to call. does anyone have any ideas?
C++ code:
#include <Python.h>
#include <iostream>
#include <string>
using namespace std;
void main()
{
cout << "Start 1 \n";
Py_Initialize();
cout << "2\n";
PyObject* my_module = PyImport_ImportModule("mypy");
cerr << my_module << "\n";
PyErr_Print();
cout << "3\n";
PyObject* my_function = PyObject_GetAttrString(my_module, "printsomething");
cout << "4\n";
PyObject* my_result = PyObject_CallObject(my_function, NULL);
Py_Finalize();
}
python code:
import re
import string
def printsomething():
print( 'Hello from Python!' )
Error Message:
ModuleNotFoundError: No module named 'mypy'
output:
The program its self runs, but I can't understand why this happens, it can't find the file with the python code.
Developer technologies C++
Sign in to answer