1

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 ?

Cyril Waechter
  • 517
  • 4
  • 16

1 Answers1

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.

Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
  • I don't understand why it's needed in Revit environment and not in a standard ipy console but it worked. You saved me again Daren. I tried wpf.__file__ to and got no result too. I tried with : import inspect inspect.getfile(wpf) and it said that wpf is a built-in module, so I thought it has no relation to search path. thanks again (I'll link you answer in rps group) – Cyril Waechter Dec 23 '14 at 01:27
  • So on the same subject as this [post](http://stackoverflow.com/questions/32013933/ironpython-wpf-withe-revitpythonshell) `clr.AddReference('IronPython.Wpf') import wpf` gives me an error that `wpf` does not exist. However there is a `Wpf` with capital `W` that I'm importing as `wpf`. But then it's still telling me there needs to be 3 arguments for the `LoadComponent()` function. – Ehsan Iran-Nejad Aug 26 '15 at 16:04