Has anyone used SciPy with IronPython? - python

I've been able to use the standard Python modules from IronPython, but I haven't gotten SciPy to work yet. Has anyone been able to use SciPy from IronPython? What did you have to do to make it work?
Update: See Numerical computing in IronPython with Ironclad
Update: Microsoft is partnering with Enthought to make SciPy for .NET.

Some of my workmates are working on Ironclad, a project that will make extension modules for CPython work in IronPython. It's still in development, but parts of numpy, scipy and some other modules already work. You should try it out to see whether the parts of scipy you need are supported.
It's an open-source project, so if you're interested you could even help. In any case, some feedback about what you're trying to do and what parts we should look at next is helpful too.

Anything with components written in C (for example NumPy, which is a component of SciPy) will not work on IronPython as the external language interface works differently. Any C language component will probably not work unless it has been explicitly ported to work with IronPython.
You might have to dig into the individual modules and check to see which ones work or are pure python and find out which if any of the C-based ones have been ported yet.

Related

Could I use Cython with 3rdparty pure python library?

I'm using Python to develop a commercial software.
But I don't want to offer source to my clients.
I knew that Cython can complie my code to binary.
But could I use Cython with 3rdparty pure python library(I mean those libraries written in pure Python)?
Cython compiles to .pyd (not pyc), which is basically a dll. In theory it should work with any python code, including 3rd party libraries, but there's no guarantee (see the first comment below). You'd also better check the licenses of the libraries you intend to use though, to make sure they don't prohibit distributing as closed source.
Your other option is something like cx_Freeze or py2exe, both of which I think compile to binary. I've never really inspected the files they produce though so you'll need to check up on that.

C TA-Lib functions in Python

I was wondering if any of you could give me guidance on whether it'd be possible to use some of these TA-LIB functions found here in a python script. I cant find the functions in any other language that I know...
I read this, so there seems to be some level of possibility, however I have little understanding of whats going on in the article since I dont know C at all. Oh and incase you are wondering TA-Lib is ported on python BUT its doesnt really build on mac and most people say they have issues with it.
So essentially, I can't get the whole app to work in swig, I was wondering if I could instead compile the function (not even sure if that makes sense) and use it in a python app (and hopefully some guidance on how to do so).
I believe there are three simple approaches you could take:
SWIG
TA-Lib comes with a Python wrapper that is generated by SWIG. It hasn't been updated in a long time, so is hard-coded to build with Python 2.3. Andy Hawkins wrote some directions to get it to work with newer versions of Python.
Cython
I wrote a TA-Lib python wrapper that uses Cython to wrap all the functions in TA-Lib, and released it on Github. It works really well for me, uses Numpy arrays, is 2-4 times faster, more "pythonic", and easier to install (works on Mac OS X) than the SWIG interface.
Ctypes
If you only need a small number of functions from the library, you can use ctypes to make calls into the TA-Lib library.
If all you need is a single function in a library, yoyu be better of using ctypes - ctypes is a Python module in the standard library that allows to you to perform calls to libraries in native code.
You just have to check on the Python console how to obtain you TA-LIB as a Python object using ctypes, and how to call the function you need. Ctypes converts ints and strings automatically to C for you - you will need to perform some function anotation for other parameter types, though.

I want to use NumPy/SciPy. Should I use Python 2 or 3?

I am about to embark on some signal processing work using NumPy/SciPy. However, I have never used Python before and don't know where to start.
I see there are currently two branches of Python in this world: Version 2.x and 3.x.
Being a neophile, I instinctively tend to go for the newer one, but there seems to be a lot of talk about incompatibilities between the two. Numpy seems to be compatible with Python 3. I can't find any documents on SciPy.
Would you recommend to go with Python 3 or 2?
(could you point me to some resources to get started? I know C/C++, Ruby, Matlab and some other stuff and basically want to use NumPy instead of Matlab.)
Both scipy and numpy are compatible with py3k. However, if you'll need to plot stuff: matplotlib is not yet officially compatible with py3k. So, it'll depend on whether your signalling processing involves plotting.
Syntactic differences are not that great between the two version.
I am using Python 2.6 with Numpy. I can confirm that Python 3 is not backward compatible. So I myself am not very confident with upgrading. Have a look at the cookbook to get started
http://www.scipy.org/Cookbook
I personally suggest you begin with 2.7, 'cause it seems to me that there is a lot of time before 2.x will become deprecated.
read more hear http://docs.python.org/dev/whatsnew/2.7.html
#SilentGhost
Scipy for python 3.2 available in beta: http://sourceforge.net/projects/scipy/files/scipy/0.10.0b2/
I am quite conservative in this respect, and so I use Python 2.6. That's what comes pre-installed on my Linux box, and it is also the target version for the latest binary releases of SciPy.
Python 3 is without a doubt a huge step forward, but if you do mainly numerical stuff with NumPy and SciPy, I'd still go for Python 2.
I can recommend Using py3k over py2.6 if possible. Especially if you're a new user, since some of the syntax changes in py3k and it'll be harder to get used the new syntax if you're starting out learning the old.
The modules you mention all have support for py3k but as SilentGhost noted you might want to check for compatibility with plotting libraries too.

List of modules working with ironpython

Is there a place that lists standard library and 3rd party modules that work with IronPython? If not, please let me know here.
Here are some I have tried:
cherrypy - works with fepy - example
comtypes: has no hope until ctypes is functional which seems far off still.
dulwich: builds after removing optional extensions from setup.py file. Imports after adding in jdhardy's zlib and subprocess modules. Seems to pass its own tests.
numpy, parts of scipy: pytools
rpyc works out of the box. Awesome library so you can remotely use cpython ojects from ironpython and vice versa
The official IronPython website has a page that lists the compatibility status of third-party libraries.
However, currently only two libraries are listed. If you're a third-party library developer and you know how well your library works with IronPython, it would be great to add it there.
pywin32 and PyODBC go away, replaced by the FCL (optionally using one of the ODBC .NET data providers if you're married to ODBC). CherryPy is pure Python and so should mostly work; I'm sure the developers would be interested in hearing about any problems. For NumPy there's Ironclad.
numpy and parts of scipy now work with ironpython: http://pytools.codeplex.com/

Python - IronPython dilemma

I'm starting to study Python, and for now I like it very much. But, if you could just answer a few questions for me, which have been troubling me, and I can't find any definite answers to them:
What is the relationship between Python's C implementation (main version from python.org) and IronPython, in terms of language compatibility ? Is it the same language, and do I by learning one, will be able to smoothly cross to another, or is it Java to JavaScript ?
What is the current status to IronPython's libraries ? How much does it lags behind CPython libraries ? I'm mostly interested in numpy/scipy and f2py. Are they available to IronPython ?
What would be the best way to access VB from Python and the other way back (connecting some python libraries to Excel's VBA, to be exact) ?
1) IronPython and CPython share nearly identical language syntax. There is very little difference between them. Transitioning should be trivial.
2) The libraries in IronPython are very different than CPython. The Python libraries are a fair bit behind - quite a few of the CPython-accessible libraries will not work (currently) under IronPython. However, IronPython has clean, direct access to the entire .NET Framework, which means that it has one of the most extensive libraries natively accessible to it, so in many ways, it's far ahead of CPython. Some of the numpy/scipy libraries do not work in IronPython, but due to the .NET implementation, some of the functionality is not necessary, since the perf. characteristics are different.
3) Accessing Excel VBA is going to be easier using IronPython, if you're doing it from VBA. If you're trying to automate excel, IronPython is still easier, since you have access to the Execl Primary Interop Assemblies, and can directly automate it using the same libraries as C# and VB.NET.
What is the relationship between
Python's C implementation (main
version from python.org) and
IronPython, in terms of language
compatibility ? Is it the same
language, and do I by learning one,
will be able to smoothly cross to
another, or is it Java to JavaScript ?
Same language (at 2.5 level for now -- IronPython's not 2.6 yet AFAIK).
What is the current status to
IronPython's libraries ? How much does
it lags behind CPython libraries ? I'm
mostly interested in numpy/scipy and
f2py. Are they available to IronPython
?
Standard libraries are in a great state in today's IronPython, huge third-party extensions like the ones you mention far from it. numpy's starting to get feasible thanks to ironclad, but not production-level as numpy is from IronPython (as witnessed by the 0.5 version number for ironclad, &c). scipy is huge and sprawling and chock full of C-coded and Fortran-coded extensions: I have no first-hand experience but I suspect less than half will even run, much less run flawlessly, under any implementation except CPython.
What would be the best way to access
VB from Python and the other way back
(connecting some python libraries to
Excel's VBA, to be exact) ?
IronPython should make it easier via .NET approaches, but CPython is not that far via COM implementation in win32all.
Last but not least, by all means check out the book IronPython in Action -- as I say every time I recommend it, I'm biased (by having been a tech reviewer for it AND by friendship with one author) but I think it's objectively the best intro to Python for .NET developers AND at the same time the best intro to .NET for Pythonistas.
If you need all of scipy (WOW, but that's some "Renaissance Man" computational scientist!-), CPython is really the only real option today. I'm sure other large extensions (PyQt, say, or Mayavi) are in a similar state. For deep integration to today's Windows, however, I think IronPython may have an edge. For general-purpose uses, CPython may be better (esp. thanks to the many new features in 2.6), unless you're really keen to use many cores to the hilt within a single process, in which case IronPython (which is GIL-less) may prove advantageous again.
One way or another (or even on the JVM via Jython, or in peculiar environments via PyPy) Python is surely an awesome language, whatever implementation(s) you pick for a given application!-) Note that you don't need to stick with ONE implementation (though you should probably pick one VERSION -- 2.5 for maximal compatibility with IronPython, Jython, Google App Engine, etc; 2.6 if you don't care about any deployment options except "CPython on a machine under my own sole or virtual control";-).
IronPython version 2.0.2, the current release, supports Python 2.5 syntax. With the next release, 2.6, which is expected sometime over the next month or so (though I'm not sure the team have set a hard release date; here's the beta), they will support Python 2.6 syntax. So, less Java to JavaScript and more Java to J# :-)
All of the libraries that are themselves written in Python work pretty much perfectly. The ones that are written in C are more problematic; there is an open source project called Ironclad (full disclosure: developed and supported by my company), currently at version 0.8.5, which supports numpy pretty well but doesn't cover all of scipy. I don't think we've tested it with f2py. (The version of Ironclad mentioned below by Alex Martelli is over a year old, please avoid that one!)
Calling regular VB.NET from IronPython is pretty easy -- you can instantiate .NET classes and call methods (static or instance) really easily. Calling existing VBA code might be trickier; there are open source projects called Pyinex and XLW that you might want to take a look at. Alternatively, if you want a spreadsheet you can code in Python, then there's always Resolver One (another one from my company... :-)
1) The language implemented by CPython and IronPython are the same, or at most a version or two apart. This is nothing like the situation with Java and Javascript, which are two completely different languages given similar names by some bone-headed marketing decision.
2) 3rd-party libraries implemented in C (such as numpy) will have to be evaluated carefully. IronPython has a facility to execute C extensions (I forget the name), but there are many pitfalls, so you need to check with each library's maintainer
3) I have no idea.
CPython is implemented by C for corresponding platform, such as Windows, Linux or Unix; IronPython is implemented by C# and Windows .Net Framework, so it can only run on Windows Platform with .Net Framework.
For gramma, both are same. But we cannot say they are one same language. IronPython can use .Net Framework essily when you develop on windows platform.
By far, July 21, 2009 - IronPython 2.0.2, our latest stable release of IronPython, was released. you can refer to http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython.
You can access VB with .Net Framework function by IronPython. So, if you want to master IronPython, you'd better learn more .Net Framework.

Categories

Resources