Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deploying IronPython script or static building an application

I created an IronPython script that imports from Python libraries, such as os, sys, etc. as well as .NET libraries.

It runs perfectly fine from my Visual Studio IronPython solution but I need to deploy this so other people who don't have IronPython or Python installed can run it.

How would I do that?

like image 708
Gezim Avatar asked Jul 31 '12 22:07

Gezim


1 Answers

Requirements:

  • ipy.exe in C:\Program Files (x86)\IronPython 2.7.1\
  • pyc.py in C:\Program Files (x86)\IronPython 2.7.1\Tools\Scripts\
  • MyProgram.py would be your program.

    1. Inside your project folder (where MyProgram.py is), create a folder called "deploy."
    2. Run cd deploy in the command prompt.
    3. Run "C:\Program Files (x86)\IronPython 2.7.1\ipy.exe" "C:\Program Files (x86)\IronPython 2.7.1\Tools\Scripts\pyc.py" /main:..\MyProgram.py /target:exe

This will generate a dll and an exe for MyProgram in the deploy folder.

If you try to run MyProgram.exe and you're importing libraries like os, you may get a No module named ....

Since, I'm using os, I get this error:

If you run "MyProgram.exe" and you're using standard libraries, you might get No module named... errors.

In my case, I got:

Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: No module na med os
...

To fix this issue, copy Lib folder from C:\Program Files (x86)\IronPython 2.7.1\ to the deploy folder you just created. Then, before you import the libraries which are throwing errors, modify MyProgram.py like this:

import sys
sys.path.append("Lib")

# Followed by library imports that were causing you trouble:
import os

As a last step, copy the following files from C:\Program Files (x86)\IronPython 2.7.1\ to deploy folder as well:

-IronPython.dll
-IronPython.Modules.dll
-Microsoft.Dynamic.dll
-Microsoft.Scripting.dll

Now you can zip up your deploy folder and and ship it!

like image 156
Gezim Avatar answered Oct 18 '22 20:10

Gezim