[英]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.