IronPython ScriptRuntime等价于CPython PYTHONPATH [英] IronPython ScriptRuntime equivalent to CPython PYTHONPATH

查看:649
本文介绍了IronPython ScriptRuntime等价于CPython PYTHONPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下导入在ipy.exe提示中工作,但在C#4.0程序中使用IronPython ScriptRuntime失败。

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program.

import ConfigParser

C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

namespace CSharpDynamic
{
	class Program
	{
		static int Main(string[] args)
		{
			ScriptRuntime python = Python.CreateRuntime();
			dynamic dynamicIni =
python.UseFile(@"c:\test\WebCast\DynamicIni.py");

			return 0;
		}
	}
}



CPython使用PYTHONPATH环境变量。

CPython uses PYTHONPATH environment variable. How do I configure this in IronPython when using ScriptRuntime?

推荐答案

要在引擎对象上使用GetSearchPaths和SetSearchPaths。您可以解析所选的env变量,并在初始化引擎时填充搜索路径。例如:

You want to use GetSearchPaths and SetSearchPaths on your engine object. You could parse the env variable of your choice and populate the search path when you initialize your engine. For example:

var engine = Python.CreateEngine(DefaultEngineOptions());
var paths = engine.GetSearchPaths();
paths.Add("c:\\my_libs");
engine.SetSearchPaths(paths);

这篇关于IronPython ScriptRuntime等价于CPython PYTHONPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆