Information in this document is subject to change without notice. The example companies, organizations, products, people, and events depicted herein are fictitious. No association with any real company, organization, product, person or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation.

 

Microsoft may have patents, patent applications, trademarked, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.

 

© Microsoft Corporation. All rights reserved.

 

Microsoft, MS-DOS, MS, Windows, Windows NT, MSDN, Active Directory, BizTalk, SQL Server, SharePoint, Outlook, PowerPoint, FrontPage, Visual Basic, Visual C++, Visual J++, Visual InterDev, Visual SourceSafe, Visual C#, Visual J#,  and Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries.

 

Other product and company names herein may be the trademarks of their respective owners.


 

This sample is subject to terms and conditions of the Shared Source License for IronPython. A copy of the license can be found in the License.html file at the root of this distribution. If you can not locate the Shared Source License for IronPython, please send an email to ironpy@microsoft.com. By using this sample in any fashion, you are agreeing to be bound by the terms of the Shared Source License for IronPython.

 

 

Python Command Line Compiler

 

 

Prerequisites

The prerequisites to successfully run this application are:

Getting Started

Navigate to the Pyc sample directory and copy the IronPython DLLs (IronPython.dll and IronMath.dll) here. The compiled executables require the presence of IronPython.dll and IronMath.dll in the current directory. If not found by the .NET runtime, the compiled executables will fail with "System.IO.FileNotFoundException: Could not load file or assembly 'IronPython, Version, ...".

Please make sure the folder structure in the Pyc directory is:

.\console_hw.py

.\IronMath.dll

.\IronPython.dll

.\other_hw.py

.\pyc.py

.\readme.htm

.\winforms_hw.py

 

Overview

This sample demonstrates the use of the Python Hosting APIs to compile Python files into a .NET executable. The behavior is essentially a command line equivalent of the IronPython Visual Studio integration sample released with the Visual Studio SDK. (The complete Visual Studio SDK integration sample can be downloaded from here.)

For the list of command line options, run:

    ipy.exe pyc.py


Command Line Options

The format of the command line for running pyc.py is as follows:

    ipy.exe pyc.py [options] file [file ...]

 

The available options are:

Examples

    import System.Windows.Forms

    form = System.Windows.Forms.Form(Text = "Hello")
    form.ShowDialog()

 

Notes

The compiled executable requires the presence of IronPython.dll and IronMath.dll in the same directory from which the compiled assembly is being executed. If IronPython.dll is not present in the current directory, the following exception will be raised:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'IronPython, ..."