Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:59:24+00:00 2026-05-22T20:59:24+00:00

I have a simple IronPython script: # Foo.py import os def main(): print( Hello

  • 0

I have a simple IronPython script:

# Foo.py
import os

def main():
    print( "Hello" )

if "__main__" == __name__:
    main()

It runs fine and prints Hello if I run it with IronPython as:

ipy Foo.py

Following the instructions given in IronPython – how to compile exe, I compiled this IronPython script to a EXE using:

ipy pyc.py /main:Foo.py /target:exe

Executing Foo.exe gives this error:

Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: No module named os
   at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)
   at DLRCachedCode.__main__$1(CodeContext $globalContext, FunctionCode $functionCode)
   at IronPython.Compiler.OnDiskScriptCode.Run()
   at IronPython.Compiler.OnDiskScriptCode.Run(Scope scope)
   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptC
ode, ModuleOptions options)

Why cannot module “os” be found? How do I fix this, so I can get a working EXE?

(Note that this is different from the question IronPython cannot import module os since the script works fine if I run with ipy.exe.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:59:24+00:00Added an answer on May 22, 2026 at 8:59 pm

    Building an Ironpython EXE that you can distribute is a bit tricky – especially if you are using elements of the standard library. My typical solution is the following:

    I copy all of the stdlib modules I need into a folder (usually all of them just for completeness) and use this script to build my exe. In this example I have two files FredMain.py and FredSOAP.py that get compiled into an EXE called Fred_Download_Tool

    import sys
    sys.path.append(r'C:\Program Files\IronPython 2.7\Lib')
    sys.path.append(r'C:\Program Files\IronPython 2.7')
    import clr
    
    clr.AddReference('IronPython')
    clr.AddReference('IronPython.Modules')
    clr.AddReference('Microsoft.Scripting.Metadata')
    clr.AddReference('Microsoft.Scripting')
    clr.AddReference('Microsoft.Dynamic')
    clr.AddReference('mscorlib')
    clr.AddReference('System')
    clr.AddReference('System.Data')
    
    #
    # adapted from os-path-walk-example-3.py
    
    import os, glob
    import fnmatch
    import pyc
    
    def doscopy(filename1):
        print filename1
        os.system ("copy %s .\\bin\Debug\%s" % (filename1, filename1))
    
    class GlobDirectoryWalker:
        # a forward iterator that traverses a directory tree
    
        def __init__(self, directory, pattern="*"):
            self.stack = [directory]
            self.pattern = pattern
            self.files = []
            self.index = 0
    
        def __getitem__(self, index):
            while 1:
                try:
                    file = self.files[self.index]
                    self.index = self.index + 1
                except IndexError:
                    # pop next directory from stack
                    self.directory = self.stack.pop()
                    self.files = os.listdir(self.directory)
                    self.index = 0
                else:
                    # got a filename
                    fullname = os.path.join(self.directory, file)
                    if os.path.isdir(fullname) and not os.path.islink(fullname) and fullname[-4:]<>'.svn':
                        self.stack.append(fullname)
                    if fnmatch.fnmatch(file, self.pattern):
                        return fullname
    
    #Build StdLib.DLL
    gb = glob.glob(r".\Lib\*.py")
    gb.append("/out:StdLib")    
    
    #print ["/target:dll",]+gb
    
    pyc.Main(["/target:dll"]+gb)
    
    #Build EXE
    gb=["/main:FredMain.py","FredSOAP.py","/target:exe","/out:Fred_Download_Tool"]
    pyc.Main(gb)
    
    
    #CopyFiles to Release Directory
    doscopy("StdLib.dll")
    doscopy("Fred_Download_Tool.exe")
    doscopy("Fred_Download_.dll")
    
    
    #Copy DLLs to Release Directory
    fl = ["IronPython.dll","IronPython.Modules.dll","Microsoft.Dynamic.dll","Microsoft.Scripting.Debugging.dll","Microsoft.Scripting.dll","Microsoft.Scripting.ExtensionAttribute.dll","Microsoft.Scripting.Core.dll"]
    for f in fl:
    
    doscopy(f)
    

    In my scripts I add the following when I am ready to compile. This allows the program to use the Standard Modules from my DLL instead of the Python Install. This is necessary if you want to distribute to people without Python installed. Just make sure you include the necessary DLL’s when you create your installer.

    #References to created DLL of python modules
    clr.AddReference('StdLib')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an IronPython script that uses the TPL and Parallel.ForEach to process files
I have simple JSF application. Everything works fine, but not navigation. It behaves like
i have simple XML file: <MyRoot> <Value key=TARGET>foo</Value> <Value key=MODEL>bar</Value> <Value key=MANUFACTURER>bla</Value> </MyRoot> and
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement
I develop tools in Autodesk Maya. Many of the tools I build have simple
Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple 2-column layout with a footer that clears both the right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.