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

查看:20
本文介绍了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:	estWebCastDynamicIni.py");

            return 0;
        }
    }
}

CPython 使用 PYTHONPATH 环境变量.使用 ScriptRuntime 时如何在 IronPython 中进行配置?

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天全站免登陆