2

In my IronPython script, I'm using standard libary modules like ConfigParser, logging and JSON.

Then I use pyc.py to create an executable. At first I ran into problems, namely '...ImportException: no module named ...' since they weren't being included in the exe and accompanying dlls.

So I ran a solution from here: IronPython: EXE compiled using pyc.py cannot import module "os" and it mostly worked.

For example, importing 'ConfigParser' would work since in the IronPython 'Lib' folder as a module, it's there as 'ConfigParser.py'. However I'm still having trouble using JSON and logging since they're inside of folders with their name (packages?).

I'm feeling that I'm just missing something simple, and probably need to read up more on python modules and how they really work, but I'm not sure what I should be looking for. Any help would be greatly appreciated.

Thanks!

EDIT:

I can't answer my own question yet, so I'll leave this here.

Somehow got it to work in a really 'hacky' way. There must be another much cleaner solution to this that I'm missing (some option in pyc.py?)

Here's what I did:

1) Made the StdLib.dll file generated from the link above (IronPython: EXE compiled using pyc.py cannot import module "os"). This would be missing the std lib packages.

2) Used SharpDevelop to compile the standard lib packages that weren't included in the above dll following the method here: http://community.sharpdevelop.net/blogs/mattward/archive/2010/03/16/CompilingPythonPackagesWithIronPython.aspx

3) Used SharpDevelop to build my program and tie together all the references. - Reference to the dlls made in step 2 - Reference to the StdLib.dll made in step 1

Again, there must be a better solution to this.

Community
  • 1
  • 1
user173326
  • 67
  • 8

1 Answers1

1

I've found two ways to compile standard library python packages:

1st way: Individually compile each package into a dll Using pyc.py, run something like (this example compiles logging package):

ipy pyc.py ".\Lib\logging\__init__.py" ".\Lib\logging\config.py" ".\Lib\logging\handlers.py" /target:dll /out:logging

This creates a logging.dll file, which you can then use like this:

import clr
clr.AddReference('StdLib') #from the compilation of non-package std libraries


clr.AddReference('logging')
import logging

**Note: This is assuming you've run the solution from IronPython: EXE compiled using pyc.py cannot import module "os" to create StdLib.dll

2nd way: Modify the compilation script that generated StdLib.dll

I changed this line:

#Build StdLib.DLL
gb = glob.glob(r".\Lib\*.py")
gb.append("/out:StdLib")   

To this:

#Build StdLib.DLL
gb1 = glob.glob(r".\Lib\*.py")
gb2 = glob.glob(r".\Lib\*\*.py")
gb3 = glob.glob(r".\Lib\*\*\*.py")
gb = list(set(gb1 + gb2 + gb3))
gb.append("/out:StdLib")

This includes the subfolders in the Lib directory which get missed in the original regex (only modules get included). Now, packages like xml, json, logging, etc. get included into StdLib.dll

Community
  • 1
  • 1
user173326
  • 67
  • 8
  • 1
    Looking back my answer should have used the directory walking class to accomplish this. I provided the class but didn't copy over the correct code. Sorry – WombatPM Jun 12 '14 at 01:53