I already attempted using py2exe (not compatible with ipy) and PYC (out of date). Can anyone point me in the direction of a good compiler?
相关问题
- Angular: ngc or tsc?
- Where is the implementation of included C++/C head
- Linking libavcodec in Cmake, find_library won'
- XCode iPhone OS Deployment Target Tool
- Is older version of flex SDK really required?
相关文章
- php module does not compile. Does not recognize “s
- Why does the C++ compiler give errors after lines
- Compile drools guided decision table into rules
- Mvn compile before exec
- Is C# code compiled to native binaries?
- Running the C# compiler from a C# program
- GCC optimization levels. Which is better?
- Who converts High Level Language to Assembly langu
You can use
pyc.py
, the Python Command-Line Compiler, which is included in IronPython since version 2.6 to compile a Python script to an executable. You find it at%IRONPYTONINSTALLDIR%\Tools\Scripts\pyc.py
on your hard disk.Example
Let's assume you have a simple script
test.py
that just prints out something to console. You can turn this into an executable with the following command-line (assuming that the IronPython directory is the current directory and thattest.py
is in there, too):Note: If you are using forms and don't want a console window to open, you want to use
/target:winexe
instead of/target:exe
.The result will be two files,
test.dll
andtest.exe
.test.dll
will contain your actual script code, whiletest.exe
is just a launcher fortest.dll
. You can distribute this EXE and DLL to other computers which do not have IronPython installed if you include the filesIronPython.dll
,Microsoft.Dynamic.dll
,Microsoft.Scripting.Core.dll
,Microsoft.Scripting.Debugging.dll
,Microsoft.Scripting.dll
,Microsoft.Scripting.ExtensionAttribute.dll
andIronPython.Modules.dll
(sometimes needed).Also see the blog entry IronPython - how to compile exe.
I had a bit of trouble trying to implement this solution. This is what I did:
C:\Program Files
ipy.exe pyc.py other_hw.py /main:console_hw.py
It gave me this error:
I made the following change to line 35:
Before:
class PycSink(Hosting.CompilerSink):
After:
class PycSink():
Saving the file proved to be a problem due to permissions, so I copied the contents of pyc.py into a new IDLE window (to create a copy), deleted the existing copy of
pyc.py
and saved the copy aspyc.py
in the same location. This takes care of permissions issues and allows changes.After making this change, I tried running the this command again:
ipy.exe pyc.py other_hw.py /main:console_hw.py
However, this time, I got the following error:
At this point, I took stock of the fact that it is now 1 AM and I have a midterm tomorrow, so I undid the changes and shut it down.
Please let me know if you have a solution, or any advancements on mine.
Yes I have found it too difficult to compile an exe so I have switched back to using standard Python. They should give a good tutorial on it on the IronPython site
This is a long standing question about which there is very little information on the internet. The only known solution I can find is at http://community.sharpdevelop.net/blogs/mattward/archive/2010/03/16/CompilingPythonPackagesWithIronPython.aspx which uses SharpDevelop. However, this solution is impractical because any semi-complex python project will do a LOT of module imports, and the SharpDevelop solution requires you to create a project per import. I started at it and gave up after about thirty new projects, better to write an automated solution!
So here's my solution, and I'll warn you right now it's not being released as a proper project for good reason:
This was written against IronPython v2.7.2 RC1 using its new standalone binary feature, and indeed it does work. You get a standalone .exe file which is totally self-contained - it needs nothing else installed. The script works by parsing the imports for the supplied script and sending the entire lot to pyc.py. That's the good news.
The bad news is as follows:
So there you go. It works, but the solution still needs a lot more maturing. Best of luck!
Check out the IronPython Samples Page
About half way down the page:
Pyc - Python Command-Line Compiler This sample shows developers how to create .NET executables directly out of IronPython scripts. The readme.htm in the download will get you started.
IronPython’s Hosting APIs can be used to compile Python scripts into DLLs, console executables, or Windows executables. The pyc.py script included in this tutorial leverages these hosting APIs and can be used to compile other Python scripts. It provides a variety of flags such as the ability to specify the target platform of the .NET assembly (e.g., x64).
While the assemblies produced by the IronPython Hosting APIs are true .NET assemblies, the dynamic nature of the Python language makes it difficult to use these from other .NET languages. In short, this means that attempting to import Python types into other .NET languages such as C# is not recommended.
Edit: Just noticed that you mentioned PYC was out of date. What makes it so? The IronPython crew seem to still be promoting it, so I would imagine that it's not that far gone.