[Ironpython-users] How to get lib json in ironpython

Markus Schaber m.schaber at codesys.com
Fri Apr 4 07:29:43 CEST 2014


Hi, Lin,

You need to provide the IronPython standard library to your application. The IronPython standard library consists of two parts: The IronPython.modules.dll (which roughly represents the "native" part of the cPython standard library) and a Directory full of python files (which is nearly identical to the python part of the cPython standard library).

It seems you already found the first part, and (as a hack) used the cPython version of the second part.

I see three options:

1) Ship the second part of the standard Library with your application as a directory tree. You just need to add the directory to sys.path (can be done by python code, or by the hosting .NET code). This way is the most similar and compatible one compared to cPython, and e. G. also implemented by CODESYS.


2) Using ZipImport: Newer versions of IronPython support ZipImport, so you could just zip the directory tree together, and add the zip file to sys.path.


3) You can compile the python files to a .NET Assembly (.dll file) using the "pyc.py" script (which should be included in recent ironpython packages).


I've never done 2 and 3 myself, but as far as I know, others have with success.

You should use the python files which are shipped with the corresponding IronPython version instead of the cPython ones, as they contain some compatibility patches and fixes. The IronPython developers intend to unify the standard library with the cPython one, but they're not there yet.

Best regards

Markus Schaber

CODESYS(r) a trademark of 3S-Smart Software Solutions GmbH

Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50

E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>

Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
Von: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] Im Auftrag von Lin LIU
Gesendet: Donnerstag, 3. April 2014 17:26
An: ironpython-users at python.org
Betreff: [Ironpython-users] How to get lib json in ironpython

Hello everyone,

    I'm a newbie of IronPython and I'm a python user since 3 years. Actually, I work on a .NET based project in which I use IronPython to call the CS libs. I encountered a problem when I wanted get lib Json in ironpython and then I put the following codes in the beginning of the script and it works.
import sys
sys.path.append("C:\Program Files\IronPython 2.7\Lib")
import json

But this solution impose the installation of ironpython.

Otherwise, putting the IronPython.dll, IronPython.Module.dll in my app directory can also help me to get some python libs, ex: re. But this doesn"t work to get lib json.

I wonder if anyone of you has the same experience as mine and already has found a DLL which contains json.

I hear that using .NET libs in script python can also get json, but I've no idea which lib to use and how to use it. Anyone can help me. Thanks a lot.

Best regards,

Lin


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140404/5b1c394e/attachment.html>


More information about the Ironpython-users mailing list