XD blog

blog page

pythonnet


2014-09-20 Magic command %%CS for IPython Notebook

The notebooks IPython offer a couple of magic command to run others language such %%R, %%octave or %%julia. I found one option for F# but nothing on something like %%CS. However, magic commands are quite easy to handle. It is not that difficult to add one which allows me to do that:

%%CS mypower System.dll
public static double mypower(double x, double y)
{
    if (y == 0) return 1.0 ;
    return System.Math.Pow(x,y) ;
}

To be able to call it that way:

mypower(3.0,3.0)

more...

2014-09-17 An issue or something to know with pythonnet

pythonnet is a module which can access .net assemblies (written in C# for example).

from clr import AddReference
AddReference("something.dll or .exe")

It only works if the DLL can be found in one path in sys.path and also if all dependencies are located in the same folder. If it is not the case, dependencies must be loaded first.

from clr import AddReference
import sys
sys.path.append("path to dependencies.dll")
AddReference("dependencies.dll")
sys.path.append("path to something.dll")
AddReference("something.dll or .exe")

2014-06-20 Python et Excel

On m'a posé récemment la question des divers moyens de travailler avec Python et Excel. J'en connais trois :


more...

2014-02-23 Python and C# in the same program

I pretty much use Python for everything, I link many of my tools with Python, having the same place to run them. However, C# is very convenient if you want to automate some processes on Windows. Since I discovered pythonnet, I do not look anymore for a way to do things in Python, I do it in C#, I make an assembly and I link it to Python.


more...

2013-10-23 Using pythonnet

I migrated over Windows 8.1 and I realized my version of pythonnet for Python did not work anymore. I got the following error:

ImportError: dynamic module does not define init function (PyInit_clr)
I did not really try to understand but I knew I had to access the sources first because the official website of pythonnet does not provide any version for python 3.x. So I looked for pythonnet on github, I found this. I got the sources which did not compile on the first try unless I apply the three following modifications: After the compilation completed (on Windows 8.1 + Visual Studio 2012, 2013), I could use the two files clr.pyd and Python.Runtime.dll the same way. There were some others modifications I do not remember exactly. Anyway, my version is located here sdpython/pythonnet.


Xavier Dupré