ImportError: No module named wpf (in Revit environment only) - User interface

℡╲_俬逩灬. 提交于 2019-12-11 06:45:32

问题


I'm able to make a simple working UI on VS launched with ipy interpreter but when I try to launch it in Revit environment (revit python shell or macro), I got the following error : ImportError: No module named wpf

wpf is a built-in module, so I don't think I forgot any reference or pythonpath.

I checked both sys.version (idea from a post on stackoverflow): import sys print sys.version

and got the same result on revitpythonshell and Ironpython console : 2.7.4 (IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.18444 (64-bit)) un2.7.4 (IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.18444 (64-bit))

Any idea ?


回答1:


I wonder... could it have to do with the search paths? I tried doing this in the ironpython console:

import wpf
wpf.__file__

but got no result, so I checked the filesystem for some other places the module could come from. So I did this:

  • Add a search path to: "C:\Program Files (x86)\IronPython 2.7\Platforms\Net40" (or wherever that is on your system)
  • Then do:

    import clr clr.AddReference('IronPython.Wpf') import wpf

On my machine that works. Of course this means you need to install IronPython on your system - RevitPythonShell ships with an IronPython version, but just includes the main dlls.



来源:https://stackoverflow.com/questions/27580543/importerror-no-module-named-wpf-in-revit-environment-only-user-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!