1

I built a Windows Form to gather information about projects. This information is then uploaded to a database.

Actually, I'm using a Python script to do that (the required information is therefore hardcoded in the script by the user).

I would like to use my WindowsForm to set the variable for my script. I'm getting an IronPython runtime exception : cannot import _psycopg from psycopg2

Here's the code that set up the variables and run the script:

 private void btn_uploaddata_Click(object sender, EventArgs e)
        {

            var engine = Python.CreateEngine();
            var scope = engine.CreateScope();
            engine.SetSearchPaths(new Collection<string>(new[]
            {
                @"C:\Python27_XY",
                @"C:\Python27_XY\DLLs",
                @"C:\Python27_XY\Lib",
                @"C:\Python27_XY\Lib\site-packages",
            }));

            scope.SetVariable("project_num", tb_projnum.Text);
            scope.SetVariable("project_name", tb_projname.Text);
            scope.SetVariable("proj_client", tb_projclient.Text);

            engine.ExecuteFile(@"path/to/script.py", scope);
        }

Is it only possible to use psycopg2 with IronPython ?

kaycee
  • 901
  • 1
  • 9
  • 35

1 Answers1

2

The psycopg2 module uses a CPython extension and will therefore not work with IronPython. There is an experimental ctypes version which is no longer supported by the author.

In any case, you need to install the according package. Did you actually try this?

ipy.exe -X:Frames -m pip psycopg2

If pip is not found you have to ensure pip first.

ipy.exe -X:Frames -m ensurepip
code_onkel
  • 2,759
  • 1
  • 16
  • 31