I'm writing C++ code which should invoke python scripts underneath. For this purpose I use cpython of python.org. Some of the python scripts execute .net code with help of python for .net and when it comes to .net all this fails. I tried to build test app to verify where it fails and found that it can't import clr module.
When I run this code it give me ImportError: No module named clr
Py_Initialize();
PyRun_SimpleString("import clr");
If I go to python console and type "import clr" everything works fine. I also checked sys.path and it contains the folder where clr.pyd located 'C:\Python27\DLLs'. I also tried setting this path in C++ by:
char* path = "C:\\Python27\\dlls";
Py_Initialize();
PySys_SetArgv(1, &path);
char* phome = Py_GetPythonHome();
But it didn't helped. In addition I don't understand why clr module is appears as clr.pyd and not .pyc like other compiled modules.
Could someone can explain why import clr fails through CPython? Is it possible to make it work?
To install clr, you have to install pythonnet library.
You can install pythonnet using following command.
pip install pythonnet
You need to call PySys_SetArgv
after Py_Initialize
appropriately to change the syspath.
I work behind a proxy server with multiple versions of python. I have a bat file I update when I need a new module, or wish to update an existing one. The first line sets the path to the version I wish to update The bat file is run from the scripts directory. Proxy IP with port "9.254.0.1:81"
SET path="C:\Programs\Python\Python3_64"
pip install --proxy="9.254.0.1:81" --upgrade pip
pip install --proxy="9.254.0.1:81" pythonnet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With