试图理解如何在IronPython中包含第三方模块
本文关键字:IronPython 包含 第三方 模块 | 更新日期: 2023-09-27 18:33:11
我在VS2010中使用IronPython。 我是Python和IronPython的新手。
我有一个导入cx_Oracle的 Python 脚本。
当我执行脚本 Main.py 时,我收到一个错误,指出找不到模块cx_Oracle。
我的 C# 代码如下所示:
public void MyMethod(string input)
{
var engine = Python.CreateEngine();
List<string> libPath = new List<string>();
libPath.Add(@"C:'Program Files (x86)'IronPython 2.7'Lib'site-packages");
engine.SetSearchPaths(libPath);
var scope = engine.CreateScope();
var eng = engine.ExecuteFile(Script, scope);
var myResult = scope.GetVariable("myInputVar");
var result = myResult(input);
}
我安装了cx_oracle模块,它将文件放在我的Python''site-packages文件夹中。
然后,我将这些相同的文件复制到我的IronPython目录中的等效文件中,我在SetSearchPaths中引用了该目录。
我错过了什么?
通过下载这个python脚本来安装包管理器pip:https://bootstrap.pypa.io/get-pip.py
打开命令提示符并运行
python get-pip.py
安装运行后:
pip install cx_Oracle
或者,如果您需要一次管理多个python环境,请查看anaconda:http://docs.continuum.io/anaconda/install
编辑:对于Ipython安装点:
ipy -X:Frames -m ensurepip
安装cx_Oracle
ipy -X:Frames -m pip install cx_Oracle