简体   繁体   English

是否可以在Windows Form应用程序中将psycopg2与IronPython一起使用?

[英]Is it possible to use psycopg2 with IronPython in a Windows Form app?

I built a Windows Form to gather information about projects. 我建立了一个Windows窗体来收集有关项目的信息。 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). 实际上,我正在使用Python脚本执行此操作(因此,所需信息由用户在脚本中进行硬编码)。

I would like to use my WindowsForm to set the variable for my script. 我想使用WindowsForm为脚本设置变量。 I'm getting an IronPython runtime exception : cannot import _psycopg from psycopg2 我遇到了IronPython运行时异常: 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 ? 只能在IronPython中使用psycopg2吗?

The psycopg2 module uses a CPython extension and will therefore not work with IronPython. psycopg2模块使用CPython扩展,因此不适用于IronPython。 There is an experimental ctypes version which is no longer supported by the author. 有一个实验性的ctypes版本 ,作者不再支持。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在 windows forms 应用程序中启动 Ironpython 交互式 window - Is there a way to launch an ironpython interactive window inside a windows forms app 是否可以在同一个应用程序中并排使用IronPython和IronRuby? - Is it possible to use IronPython and IronRuby side by side in the same Application? 是否可以在Windows App中使用System.Net.Mail? - Is it possible to use System.Net.Mail in a Windows App? 是否可以在 Windows docker 容器中运行的 dotnet 核心应用程序中使用 EPPlus? - Is it possible to use EPPlus in dotnet core app running in a windows docker container? 是否可以从非Windows Store应用程序使用RoGetMetaDataFile - Is it possible to use RoGetMetaDataFile from non Windows Store App c#Windows服务是否可以使用app.config - c# Windows service is it (possible) to use the app.config 在JetBrains PyCharm上使用IronPython - Use IronPython on JetBrains PyCharm 我不能在 c#(Windows 窗体应用程序)中使用变量 - I can't use the variable in c# (Windows Form App) 如何在c#console(windows form)app中使用WinRT组件? - How to use a WinRT component in c# console(windows form) app? 在Windows窗体应用程序中使用StronglytypedResourceBuilder生成的多语言资源 - Use multilanguage resources generated by StronglytypedResourceBuilder in windows form app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM