ironpython

Custom IronPython import resolution

瘦欲@ 提交于 2019-11-27 02:03:42
问题 I am loading an IronPython script from a database and executing it. This works fine for simple scripts, but imports are a problem. How can I intercept these import calls and then load the appropriate scripts from the database? EDIT: My main application is written in C# and I'd like to intercept the calls on the C# side without editing the Python scripts. EDIT: From the research I've done, it looks like creating your own PlatformAdaptationLayer is the way you're supposed to to implement this,

How can I redirect the stdout of IronPython in C#?

痞子三分冷 提交于 2019-11-27 01:58:18
问题 I have the following: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { try { var strExpression = @" import sys sys.stdout=my.write print 'ABC' "; var engine = Python.CreateEngine(); var scope = engine.CreateScope(); var sourceCode = engine.CreateScriptSourceFromString(strExpression); scope.SetVariable("my", this); var actual = sourceCode.Execute<string>(scope); textBox1.Text += actual; } catch (System

How to install numpy and scipy for Ironpython27? Old method doesn't work

故事扮演 提交于 2019-11-27 01:46:40
I think this is the most popular way to do it before: https://pytools.codeplex.com/wikipage?title=NumPy%20and%20SciPy%20for%20.Net But this link is no longer exist: https://store.enthought.com/repo/.iron/ I recently found a clone for the instruction, and also found a clone of ironpkg-1.0.0.py on github. But http://www.enthought.com/repo/.iron/eggs/index-depend.txt is no longer exists in the internet(I googled it, but failed to find it) Getting started with SciPy for .NET 1.) IronPython Download and install IronPython 2.7, this will require .NET v4.0. 2.) Modify PATH Add the install location on

Importing external module in IronPython

你离开我真会死。 提交于 2019-11-27 01:41:06
问题 I'm currently working on an application written in C#, which I'm embedding IronPython in. I generally have no problems about it, but there's one thing that I don't know how to deal with. I want to import an external module into the script. How can I do that? Simple import ext_lib doesn't work. Should I add a path to the lib to sys.path ? Maybe it is possible to copy the lib's .py file into app directory and import from there? EDIT: I finally chosen another solution - compiled my script with

Debugging IronPython scripts in hosted (embedded) environment

 ̄綄美尐妖づ 提交于 2019-11-27 00:11:34
问题 I'm writing a C# application which has IronPython (2.0.1) embedded in it. The idea is to expose portions of the application to the IronPython scripts, which the users write. I want to provide the ability to the users to be able to debug the scripts written by them, using the Visual Studio Debugger. Note that the scripts are run in the hosted environment and not through the IronPython executable (ipy.exe). After a bit of Reflector magic on the IronPython assemblies, I came up with something

IronPython: EXE compiled using pyc.py cannot import module “os”

 ̄綄美尐妖づ 提交于 2019-11-26 23:56:03
问题 I have a simple IronPython script: # Foo.py import os def main(): print( "Hello" ) if "__main__" == __name__: main() It runs fine and prints Hello if I run it with IronPython as: ipy Foo.py Following the instructions given in IronPython - how to compile exe , I compiled this IronPython script to a EXE using: ipy pyc.py /main:Foo.py /target:exe Executing Foo.exe gives this error: Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: No module named os at Microsoft.Scripting

How can I call (Iron)Python code from a C# app?

一曲冷凌霜 提交于 2019-11-26 23:46:02
Is there a way to call Python code, using IronPython I assume, from C#? If so, how? The process is simple, especially in a C#/.NET 4 application where support for dynamic languages have been improved via usage of the dynamic type. But it all ultimately depends on how you intend to use the (Iron)Python code within your application. You could always run ipy.exe as a separate process and pass your source files in so they may be executed. But you probably wanted to host them in your C# application. That leaves you with many options. Add a reference to the IronPython.dll and Microsoft.Scripting.dll

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

我只是一个虾纸丫 提交于 2019-11-26 23:22:47
问题 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:\test\WebCast\DynamicIni.py"); return 0; } }

What is the equivalent of the C# “using” block in IronPython?

回眸只為那壹抹淺笑 提交于 2019-11-26 23:13:49
问题 What's the equivalent of this in IronPython? Is it just a try-finally block? using (var something = new ClassThatImplementsIDisposable()) { // stuff happens here } 回答1: IronPython supports using IDisposable with with statement, so you can write something like this: with ClassThatImplementsIDisposable() as something: pass 回答2: IronPython (as of the 2.6 release candidates) supports the with statement, which wraps an IDisposable object in a manner similar to using. 回答3: With statement. For

What's the simplest way to access mssql with python or ironpython?

会有一股神秘感。 提交于 2019-11-26 22:37:34
问题 I've got mssql 2005 running on my personal computer with a database I'd like to run some python scripts on. I'm looking for a way to do some really simple access on the data. I'd like to run some select statements, process the data and maybe have python save a text file with the results. Unfortunately, even though I know a bit about python and a bit about databases, it's very difficult for me to tell, just from reading, if a library does what I want. Ideally, I'd like something that works for