0

I compiled a .dll file in ironpython, by using the following code:

import clr

clr.CompileModules('C:/example.dll', 'C:/example.py')

It essentially compiles the .py file to .dll. The only problem with this is that it creates a file with no information about the Company, Language, File Version etc. In fact the File Version is always: 0.0.0.0.

I was wondering if there is a way to at least alter the File Version (change it to something other than 0.0.0.0). I googled and found a similar topic in here on stackoverflow. I tried three methods:

1) One with Visual Studio (File->Open-> find .dll, Edit->Add Resource->Version click New. In the new Version tab, change FILEVERSION and PRODUCTVERSION)

2) Another one by using the Change version 2012 application

3) And third one by using: Simple Version Resource Tool for Windows 1.0.10

None of them worked. For some reason looks like the structure of the .dll assembly created with ironpython is different than the .NET one created with VB or C#.

Does anyone know how to change the File Version from 0.0.0.0 to something else?

Thank you.

Community
  • 1
  • 1
marco
  • 899
  • 5
  • 13
  • 21

1 Answers1

1

You can use the pyc.py file packaged into IronPython to compile your file into a .dll file. The file is located in the directory IronPython 2.7\Tools\Scripts.

If we open pyc.py for editing, you'll see the different things it can do.

pyc: The Command-Line Python Compiler

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

Options:
/out:output_file                          Output file name (default is main_file.<extenstion>)
    /target:dll                               Compile only into dll.  Default
    /target:exe                               Generate console executable stub for startup in addition to dll.
    /target:winexe                            Generate windows executable stub for startup in addition to dll.
    @<file>                                   Specifies a response file to be parsed for input files and command line options (one per line)
    /file_version:<version>                   Set the file/assembly version
    /? /h                                     This message    

EXE/WinEXE specific options:
    /main:main_file.py                        Main file of the project (module to be executed first)
    /platform:x86                             Compile for x86 only
    /platform:x64                             Compile for x64 only
    /embed                                    Embeds the generated DLL as a resource into the executable which is loaded at runtime
    /standalone                               Embeds the IronPython assemblies into the stub executable.
    /mta                                      Set MTAThreadAttribute on Main instead of STAThreadAttribute, only valid for /target:winexe
    /file_info_product:<name>                 Set product name in executable meta information
    /file_info_product_version:<version>      Set product version in executable meta information
    /file_info_company:<name>                 Set company name in executable meta information
    /file_info_copyright:<info>               Set copyright information in executable meta information
    /file_info_trademark:<info>               Set trademark information in executable meta information

Example:
    ipy.exe pyc.py /main:Program.py Form.py /target:winexe

One thing that I personally like to do is move pyc.py from the Scripts folder to the IronPython folder along with my python file as well.

Assuming you also do this, you would open command prompt as administrator and navigate to the IronPython folder.

cd "Program Files (x86)\IronPython 2.7"

Then you would want to compile your python file as a .dll and set the file version using pyc.py. To do that, you're going to want to type in:

ipy.exe pyc.py /main:example.py /target:dll /file_version:0.0.0.1

If you want to add a company name, and other items as well, you simply have to pass those option to the pyc.py script.

ipy.exe pyc.py /main:Program.py Form.py /target:winexe /file_info_company:Company
David
  • 131
  • 4
  • 9
  • Thank you for the great reply Alveno! One thing I noticed is that unlike ```clr.CompileModules```, this method requires all the modules that I am importing in Form.py to be in the same folder where Form.py is. But even when I do that, I am still getting a strange error message: ```AttributeError: 'LightException' object has no attribute 'Host'```. Any idea why is this happening? – marco Feb 04 '16 at 20:48
  • The problem may be that even though the modules you are using are in the same folder, the program doesn't know where to look for them. Have you tried appending the path where the modules are? To do this, you will need to try: `sys.path.append(current_dir)` where _current_dir_ is the folder of the modules. – David Feb 04 '16 at 21:43
  • I need to add ```sys.path.append(current_dir)``` to my ```Form.py``` (I did not include the ```/main:Program.py``` in command prompt call)? – marco Feb 04 '16 at 21:51
  • You will need to add `sys.path.append(curent_dir)` to your Form.py file before you import any modules. Your command prompt call should look like: `ipy.exe pyc.py /main:Form.py /target:dll /file_version:0.0.0.1' or whatever version your project is. – David Feb 04 '16 at 22:20
  • Looks like I made a mistake with the prompt call. Thank you. This is how it looks like now: ```D:/compile_dll/ipy.exe D:/compile_dll/pyc.py /main:D:/compile_dll/example.py /target:dll /file_version:0.0.0.1```. It is giving me the following error:```SystemError: The given path's format is not supported```. An error emerges in pyc.py, line 151: ```clr.CompileModules(output + '.dll', mainModule = main_name, *files)``` and line 159: ```Main(sys.argv[1:])```. – marco Feb 04 '16 at 22:35
  • If you have ipy.exe, pyc.py, and example.py in the same folder it is easier to run the `cd` command in the command prompt to navigate to that folder. Once you open your command prompt type: `cd "D:\compile_dll\"` Then type the pyc.py command which would be more simple now: `ipy.exe pyc.py /main:example.py /target:dll /file_version:0.0.0.1`. Make sure that your slashes are correct. Use `\\` to denote file paths. – David Feb 04 '16 at 22:57
  • Thank you. It didn't work. I tried inserting the ```/out:example.dll``` option too, like so: ```ipy.exe pyc.py /main:example.py /out:example.dll /file_version:0.0.0.1``` or like this: ```ipy.exe pyc.py /main:example.py /out:example.dll /target:dll /file_version:0.0.0.1```. Still the upper ```The given path's format is not supported``` error message appeared in pyc.py in all three cases. – marco Feb 04 '16 at 23:08
  • Reading through your comment about your error in pyc.py. I took a look at lines 151 and 159, and they do not match with my pyc.py file. Those lines correlate to lines 324 and 332 on the version I use. What version of IronPython are you using? – David Feb 04 '16 at 23:27
  • I am using IronPython 2.7. Here is my pyc.py uploaded: ```https://www.dropbox.com/s/pm6mkklk4guhfyu/pyc.py?dl=0``` – marco Feb 04 '16 at 23:31
  • That is very different from the version I use. Try using this. `https://www.dropbox.com/s/kjv6pzdmm5yrr0p/pyc.py?dl=0` – David Feb 04 '16 at 23:34
  • Thank you. That worked. It saved "example.dll". The only problem now is that it still says that its file version is: ```0.0.0.0```. I also tried adding the ```/file_info_company:someInfo```, but that also was not inserted in the newly saved "example.dll" file. Can you please upload your ipy.exe too? – marco Feb 04 '16 at 23:42
  • Hi @D. Alveno . Do you mind if I ask what version of ironpython do you use? As our pyc.py were different, the ipy.exe might too. Thank you. – marco Feb 16 '16 at 00:47
  • @marco, I am using version 2.7 of IronPython. – David Feb 16 '16 at 16:42
  • `pyc.py` was deleted from IronPython, and extracting it from IronPython's git history and running it with version 2.7.12 no longer works. – Tinister Aug 05 '22 at 22:57