Deploy IronPython script or static build application

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

It works great with my Visual Studio IronPython solution, but I need to deploy it so that other people who don't have the IronPython or Python application installed can run it.

How can I do it?

+4
source share
1 answer

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 will be your program.

    • In the project folder (where MyProgram.py ) create a folder called "deploy."
    • Run cd deploy at the command prompt.
    • 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 create a dll and exe for MyProgram in the deploy folder.

If you try to run MyProgram.exe and you import libraries like os , you can get No module named ...

Since I use os , I get this error:

If you run "MyProgram.exe" and you use the standard libraries, you may get No module named... errors.

In my case, I got:

Unhandled exception: IronPython.Runtime.Exceptions.ImportException: no na med os module
...

To fix this problem, copy the Lib folder from C:\Program Files (x86)\IronPython 2.7.1\ to the deploy folder that you just created. Then, before importing libraries that throw errors, modify MyProgram.py as follows:

 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 the C:\Program Files (x86)\IronPython 2.7.1\ folder to deploy :

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

Now you can zip the deploy folder and send it!

+10
source

All Articles