当我的IronPython程序到达该行时
import wx
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
A first chance exception of type
'IronPython.Runtime.Exceptions.PythonImportErrorException' occurred in IronPython.dll
Additional information: No module named _core_
Run Code Online (Sandbox Code Playgroud)
虽然我有文件wx\_core_.pyd.此外,在尝试导入之前,我有以下几行:
sys.path.append('c:\\Python24\\Lib\\site-packages')
sys.path.append('c:\\Python24\\Lib\\site-packages\\wx-2.6-msw-unicode')
sys.path.append('c:\\Python24\\Lib\\site-packages\\wx-2.6-msw-unicode\\wx')
sys.path.append('c:\\Python24\\Lib\\site-packages\\wx-2.6-msw-unicode\\wx\\lib')
sys.path.append('c:\\Python24\\Lib\\site-packages\\wx-2.6-msw-unicode\\wxpython\\lib')
sys.path.append('c:\\Python24\\Lib\\site-packages\\wxaddons')
Run Code Online (Sandbox Code Playgroud)
我希望IronPython能够找到所需的一切.
我正在尝试使用拦截 Python __setattr__ 和 __getattr__ 魔术方法的方法在 C# 中实现一个类。我发现了这个错误报告:
http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=8143
但那是从 2008 年开始的,我在任何地方都找不到 ICustomAttributes 或 PythonNameAttribute。我也没有在 Interfaces.cs 中看到任何有用的东西。有人可以指出我正确的方向吗?
所以我有一个基本的 ZIPPED IronPython(2.6 或 2.6.1),我只需解压缩,启动 ipy.exe,输入“import os”并按 Enter 键。发生以下输出:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named os
Run Code Online (Sandbox Code Playgroud)
即使我先导入 clr 它也不起作用。要做什么呢?
我用谷歌搜索过这个问题,但没有相关答案。最接近的想法是这个(但不起作用):
import clr
clr.AddReference("IronPython")
clr.AddReference("IronPython.Modules")
import os
Run Code Online (Sandbox Code Playgroud) 是否可以在WPF应用程序中使用AvalonEdit控件作为ironPython脚本编辑器?要求是具有语法突出显示和内联脚本验证.如果可能的话,intellisense会更好.如果不是AvalonEdit,请建议任何其他此类控件(即使是商业用途)可用于此目的.
提前致谢
是的我知道,这似乎与之前成千上万次询问的问题相同.但不,这不是真的 - 至少我是这么认为的.
我使用IronPython并想调用C#方法:
bool GetClassInstance<T>(out T myClassInstance)
Run Code Online (Sandbox Code Playgroud)
通过python调用此函数看起来像:
myClassInstance = None
myInstance.GetClassInstance[ClassType](myClassInstance)
Run Code Online (Sandbox Code Playgroud)
问题是以下错误消息:
expected StrongBox[ClassType], got NoneType (ArgumentTypeException)
Run Code Online (Sandbox Code Playgroud)
现在我有两个问题:
非常感谢!!
使用Python for .Net框架,我尝试从C#.dll文件调用方法。此方法具有以下参数:
public static void ExternalFunction(
String Arg1,
ref Double[]& Arg2,
);
Run Code Online (Sandbox Code Playgroud)
我知道.Net框架会将Python浮点数转换为双精度数。现在,我想知道如何制作一个数组(双精度)并将其作为对外部方法的引用。
我有以下代码:
import clr
clr.AddReference("MyDll")
from MyLib import MyClass
myName = "Benjamin"
r = MyClass.ExternalFunction(myName, 0.0);
print "Result: %s"%r
Run Code Online (Sandbox Code Playgroud) 我的c#代码:
//Create the ScriptRuntime
engine = Python.CreateEngine();
//Create the scope for the ScriptEngine
scope = engine.CreateScope();
string pyfile = "D:\\MyAddin\\test.py";
ScriptSource source = engine.CreateScriptSourceFromFile(pyfile);
var rt = source.Execute(scope);
Run Code Online (Sandbox Code Playgroud)
和我的test.py:
import os
import sys
...
print("test")
...
Run Code Online (Sandbox Code Playgroud)
我在构建时没有问题,但在运行时VS给我一个错误"无法导入模块"os"".错误在哪里?
在 IronPython 脚本中,我尝试将Grade对象(在 C# 中创建)的属性(类型为 )与枚举的可能值之一进行比较Grade。例如:
if (myObject.TotalGrade == Grade.Fail):
Run Code Online (Sandbox Code Playgroud)
现在,我在获得这两个值后设置了一个断点,并且我确实可以验证它们都保持“失败”;然而,检查失败,程序继续执行下一个子句。python 相等运算符不适合 C# 枚举吗?
附加信息:我已从GradeC# 导入枚举,如下所示。
import clr
clr.AddReferenceToFile("mydll.dll")
from mydll import Grade
Run Code Online (Sandbox Code Playgroud) 我想使用 c# 在 IronPython 中运行一些代码。在此代码中我需要使用 numpy。所以我尝试使用以下命令安装它:
ipy -X:Frames -m pip install -U numpy
Run Code Online (Sandbox Code Playgroud)
不幸的是,我收到一个错误和一条返回消息,告诉我安装不成功。错误信息如下:
Using cached https://files.pythonhosted.org/packages/3a/20/c81632328b1a4e1db65f45c0a1350a9c5341fd4bbb8ea66cdd98da56fe2e/numpy-1.15.0.zip
Installing collected packages: numpy
Running setup.py install for numpy ... error
Complete output from command "C:\Program Files\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\mbhamida\\appdata\\local\\temp\\pip-build-t61kxu\\numpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\mbhamida\appdata\local\temp\pip-y91bz0-record\install-record.txt --single-version-externally-managed --compile:
Running from numpy source directory.
Note: if you need reliable uninstall behavior, then install
with pip instead of using `setup.py install`:
- `pip install .` (from a git repo or …Run Code Online (Sandbox Code Playgroud) 所以我不断收到这个错误,当我谷歌为它,最常见的解决方法是确保一个类的所有方法都有'self'作为第一个参数.这是错误:
File "C:\Users\me\Documents\Project\code\model\TrainEvent.py", line 9, in
NameError: global name 'self' is not definedPress any key to continue . . .
这似乎是一个简单修复的常见错误,除了我的所有方法都将self作为第一个参数.然后我意识到回溯只是指向声明类名的行.它没有指向我用self调用方法的行.在此之前很久就会出现此错误.事实上,它似乎是在进口时提出的.这是TrainEvent.py.
from xml.etree.ElementTree import Element
class TrainEvent(object):
def __init__(self, element):
self._element = element
self.MsgId = self.__tagGrab('MsgId')
self.MsgTime = self.__tagGrab('MsgTime')
self.Offset = self.__tagGrab('Offset')
self.TranId = self.__tagGrab('TranId')
self.Portal = self.__tagGrab('Portal')
moveElem = self._element.find('Move')
self.StartTime = self.__tagGrab('StartTime', moveElem)
self.EndTime = self.__tagGrab('EndTime', moveElem)
self.Type = self.__tagGrab('Type', moveElem)
carElem = self._element.find('Car')
self.Name = self.__tagGrab('Name', carElem)
self.UniqueId = self.__tagGrab('UniqueId', carElem)
self.Orientation = self.__tagGrab('Orientation', carElem)
self.Wells = …Run Code Online (Sandbox Code Playgroud) ironpython ×10
c# ×5
python ×5
.net ×3
avalonedit ×1
enums ×1
import ×1
python-2.7 ×1
python.net ×1
self ×1
syntax ×1
types ×1
wpf ×1
wxpython ×1