a problem using scipy/numpy for IronPython .Net

May 27, 2011 at 6:54 AM

 I installed numpy/scipy through link http://www.enthought.com/repo/.iron/.

In ironpython interactive window, I got the following error for "import numpy":

>>> import scipy
numeric.py: Temporarily filtering symbol 'int_asbuffer'
numeric.py: Temporarily filtering symbol 'set_numeric_ops'
numeric.py: Temporarily filtering symbol 'can_cast'
numeric.py: Temporarily filtering symbol 'bitwise_not'
scipy.__init__: Comment out delete of linalg from numpy since it doesn't exist yet.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\IronPython 2.7\lib\site-packages\scipy\__init__.py", line 125, in <module>
    pkgload = PackageLoader()
  File "C:\Program Files\IronPython 2.7\lib\site-packages\numpy\_import_tools.py", line 15, in __init__
    self.parent_frame = frame = sys._getframe(_level)
AttributeError: 'module' object has no attribute '_getframe'

My ironpython version is : IronPython 2.7 (2.7.0.30) on .NET 4.0.30319.225.

Who can give me some suggestions?

thanks!

May 31, 2011 at 3:22 PM

The issue is that SciPy makes use of the CPython API for inspecting the current stack frame which  IronPython doesn't enable by default because of a small runtime performance hit.   You can turn on this functionality by passing the command line argument "-X:Frames" to on the command line.  For example:

ipy.exe -X:Frames -c "import scipy"

 

Regards,

Jason

Sep 8, 2011 at 6:42 PM

I am having the same problem and this is working great from the command line, but how do I do this from VS? Is there a way to do this programmatically?

Many thanks.

Editor
Sep 8, 2011 at 6:51 PM

You can set -X:Frames in the interactive window options:

  1. Go to: Tools -> Options -> Python Tools -> Interactive Windows -> IronPython 2.7
  2. Set "Interpreter Options" to "-X:Frames"
Sep 8, 2011 at 7:00 PM

Thanks Jason,

I have tried this but it doesn’t seems to make a difference. Here is the error I get on the interactive interpreter:

>>>

>>>

>>> import scipy

Traceback (most recent call last):

File "<string>", line 1, in <module>

File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\scipy\__init__.py", line 124, in <module>

pkgload = PackageLoader()

File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\numpy\_import_tools.py", line 15, in __init__

self.parent_frame = frame = sys._getframe(_level)

AttributeError: 'module' object has no attribute '_getframe'

>>>

From: joxn [email removed]
Sent: Thursday, September 08, 2011 10:52 AM
To: ychuri@isensesystems.com
Subject: Re: a problem using scipy/numpy for IronPython .Net [pytools:259192]

From: joxn

You can set -X:Frames in the interactive window options:

1. Go to: Tools -> Options -> Python Tools -> Interactive Windows -> IronPython 2.7

2. Set "Interpreter Options" to "-X:Frames"

Editor
Sep 8, 2011 at 7:50 PM

If you just made that change inside Visual Studio with the IronPython Interactive open, you'll have to reset the interactive window (click the blue button on the IronPython 2.7 Interactive window's toolbar).

If you did reset the interactive, and it still isn't working, it would be interesting to see what the command line is that we're passing to create the IronPython process.  In a Powershell window, do:

PS> ( Get-WmiObject Win32_Process -Filter "Name like '%ipy%'" ).CommandLine

On my system (where "import scipy" is working for me in the IronPython interactive window) I see this output:

<tt>"C:\Program Files (x86)\IronPython 2.7\ipy.exe" -X:Frames "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_repl.py" --port 9947 --enable-attach --execution_mode Standard</tt>

Sep 8, 2011 at 8:05 PM

Thanks for your help. Like I said in a previous email, I can run my application with the interpreter, however, when running the debugger (F5) the import still fails. Here is the output I am getting from Powershell:

"C:\Program Files (x86)\IronPython 2.7\ipy.exe" -X:Frames "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\

IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_repl.py" --port 51281

From: joxn [email removed]
Sent: Thursday, September 08, 2011 11:50 AM
To: ychuri@isensesystems.com
Subject: Re: a problem using scipy/numpy for IronPython .Net [pytools:259192]

From: joxn

If you just made that change inside Visual Studio with the IronPython Interactive open, you'll have to reset the interactive window (click the blue button on the IronPython 2.7 Interactive window's toolbar).

If you did reset the interactive, and it still isn't working, it would be interesting to see what the command line is that we're passing to create the IronPython process. In a Powershell window, do:

PS> ( Get-WmiObject Win32_Process -Filter "Name like '%ipy%'" ).CommandLine

On my system (where "import scipy" is working for me in the IronPython interactive window) I see this output:

"C:\Program Files (x86)\IronPython 2.7\ipy.exe" -X:Frames "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_repl.py" --port 9947 --enable-attach --execution_mode Standard

Sep 8, 2011 at 8:15 PM

 

Thanks for your help. I can run my application with the interpreter, however, when running the debugger (F5) the import still fails. Here is the output I am getting from Powershell:

 

"C:\Program Files (x86)\IronPython 2.7\ipy.exe" -X:Frames "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\

IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_repl.py" --port 51281

 

Editor
Sep 8, 2011 at 9:35 PM
Edited Sep 8, 2011 at 9:37 PM

You can specify -X:Frames on a project-by-project basis as well:

  1. Go to: Project -> Properties -> Debug tab 
  2. Set "Interpreter Arguments" to "-X:Frames"

Edit: I suggest also setting "Launch Mode" to "Standard Python Launcher" unless you need to debug C# code

Sep 8, 2011 at 9:52 PM

Ok... so now I can run the application successfully by pressing F5 but it does not break if I place a breakpoint in the code. Why is that? 

Can you reference any good documentation that can help me through this? 

(did change the "Launch Mode" to "Standard Python Launcher" - thanks!)

Editor
Sep 8, 2011 at 11:58 PM

And that's a bug! It looks like scipy is changing settrace on us.

If you switch back to IronPython (.NET) Launcher you will hit the breakpoint; this isn't as nice a debugging experience, but it will work.

I opened bug 512 to track.

Thank you for being patient with us and for reporting your issues as they come up; it is really appreciated.

Sep 9, 2011 at 12:16 AM

No, that's not the case for me. If I switch back to  IronPython (.NET) Launcher scipy does import properly. I can only get it to load correctly in Standard Python launcher but than...no debugging capabilities.