English 中文(简体)
IronPython ScriptRuntime equivalent to CPython PYTHONPATH
原标题:

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

import ConfigParser

C# code:

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 uses PYTHONPATH environment variable. How do I configure this in IronPython when using ScriptRuntime?

最佳回答

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);
问题回答

暂无回答




相关问题
Create a new Tuple with one element modified

(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations) ...

Why can t I import my C# type into IronPython?

I have some types in a C# library I wrote, e.g.: namespace SprocGenerator.Generators { public class DeleteGenerator : GeneratorBase { public DeleteGenerator(string databaseName, ...

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program. import ConfigParser C# code: using System; using System.Collections.Generic; using ...

Rollback in Ironpython using System.Data.SqlClient

I am unable to rollback using the following code snippet and need help: import clr import sys clr.AddReference( System.Data ) from System.Data.SqlClient import SqlConnection, SqlParameter, ...

Nonblocking webserver on .Net for Comet applications

I am trying to implement a Comet style (e.g. chat) application using IronPython. While I don t need to scale to twitter like dimensions, it is vital that the response time is lightening fast. All ...

IronPython asp.net IntelliSense

I m trying IronPython for asp.net, I got a simple CRUD screen to work. I ve read IntelliSense doesnt work for IronPython, but is there any way to get rid of Visual Studio underlining all the lines ...

C# Running IronPython On Multiple Threads

I have a WPF app that controls audio hardware. It uses the same PythonEngine on multiple threads. This causes strange errors I see from time to time where the PythonEngines Globals dictionary has ...

热门标签