我刚刚安装了Iron Python。当我在终端中打开它时,它显示已安装。当我在Visual Studio中寻找.dll时,我可以找到它们并将它们添加到项目中。我遵循的是Microsoft网站上的教程。一切都进行得很好,直到我结束...
保存文件,然后按CTRL + F5生成并运行该应用程序。
哪个时候出现错误。
未处理的异常:System.IO.DirectoryNotFoundException:找不到路径'C:\ Program>文件(x86)\ IronPython 2.7.9 for .NET 4.0 \ Lib'的一部分。在System.IO .__ Error.WinIOError(Int32 errorCode,可能是StringFullPath)在System.IO.Directory.SetCurrentDirectory(字符串路径)在> C:\ Users \ scott \ source \ repos \ DynamicIronPythonSample \ Program.cs:line 17]中的DynamicIronPythonSample.Program.Main()
这是我指的是Walkthrough: Creating and Using Dynamic Objects (C# and Visual Basic)
如何解决此问题?第17行是Program.cs中的这一行
System.IO.Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\IronPython 2.7.9 for .NET 4.0\Lib");
整个脚本
using Microsoft.Scripting.Hosting; using IronPython.Hosting; using System; using System.Linq; namespace DynamicIronPythonSample { class Program { static void Main() { // Set the current directory to the IronPython libraries. System.IO.Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\IronPython 2.7.9 for .NET 4.0\Lib"); // Create an instance of the random.py IronPython library. Console.WriteLine("Loading random.py"); ScriptRuntime py = Python.CreateRuntime(); dynamic random = py.UseFile("random.py"); Console.WriteLine("random.py loaded."); // Initialize an enumerable set of integers int[] items = Enumerable.Range(1, 7).ToArray(); // Randomly shuffle the array of integers by using IronPython. for (int i = 0; i < 5; i++) { random.shuffle(items); foreach (int item in items) { Console.WriteLine(item); } Console.WriteLine("-------------------"); } } } }
。NET 4.0.30319.42000(64位)上的IronPython 2.7.9(2.7.9.0)输入“帮助”,“版权”,“信用”或“许可证”以获取更多信息。
。NET v4.0.30319
我刚刚安装了Iron Python。当我在终端中打开它时,它显示已安装。当我在Visual Studio中寻找.dll时,我可以找到它们并将它们添加到项目中。我正在沿着...
最后使它起作用。 Microsoft确实提高了该教程的质量。不仅路径错误,而且IronPython运行时还有其他错误。这就是我最终得到的。谢谢那些提供帮助的人。