Using the Windows "embedded" distribution of Python

Paul Moore p.f.moore at gmail.com
Thu Sep 29 10:03:36 EDT 2016


On Thursday, 29 September 2016 12:56:28 UTC+1, eryk sun  wrote:
>> Oh, wow. Now you mention it, I recall that convention (from somewhere). >> I'll investigate that option (although it may not suit my use case, as
>> I want multiple exes in the one "main" directory sharing a single
>> "local" Python runtime).
> 
> In that case you can use an application manifest with a dependent
> assembly. Say embedded Python 3.6 is in the "py3embed" subdirectory.
> Add the following manifest file to that directory:
> 
> py3embed.manifest:
> 
>     <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>     <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
>         <assemblyIdentity name="py3embed"
>                           version="3.6.111.1013"
>                           type="win32"
>                           processorArchitecture="amd64" />
>         <file name="python3.dll" />
>         <file name="python36.dll" />
>         <file name="vcruntime140.dll" />
>     </assembly>

Cool. So this is all the SxS stuff that I never really understood, right? :-) I guess I can assume from this:

1. The filename py3embed.manifest isn't relevant (you explain file naming below).
2. assemblyIdentity name="py3embed" is what says to look in a subdirectory "py3embed" that's located next to the executable.
3. The "version" in the manifest doesn't really matter much.
4. I only need to name python3.dll, python36.dll and vcruntime140.dll as these are the only DLLs loaded statically?

> Add this assembly as a dependency in the application manifest, either
> embedded in the executable (resource #1) or as a separate file named
> the same as the executable plus ".manifest", e.g. "app.exe.manifest".

Using a separate file seems easiest (and certainly the way to go for testing) but I'm not sure how I'd embed the manifest using command line tools. I'm leveraging distutils to build my exe at the moment:

    from distutils.ccompiler import new_compiler
    import distutils.sysconfig
    import sys
    import os

    cc = new_compiler()
    exe = 'myapp'
    cc.add_include_dir(distutils.sysconfig.get_python_inc())
    cc.add_library_dir(os.path.join(sys.base_exec_prefix, 'libs'))
    objs = cc.compile(['myapp.c'])
    cc.link_executable(objs, exe)

But the ccompiler interface doesn't have anything to add in a resource or manifest, so I think I'm going to need to switch to using the command line directly for this.

> You can start with the manifest that's used by python.exe, from
> PC\python.manifest.
> 
>   <dependency>
>     <dependentAssembly>
>       <assemblyIdentity name="py3embed"
>                         version="3.6.111.1013"
>                         type="win32"
>                         processorArchitecture="amd64" />
>     </dependentAssembly>
>   </dependency>

Thanks for your help on this. My C skills are *very* rusty (going much beyond "cl /c foo.c" sends me to the manuals these days) so I appreciate all the help.

I'm off now to do a whole load of experimenting - you've given me a lot to work with :-)

Paul.

PS Is there any readable documentation on the SxS stuff anywhere, written for C programmers? Microsoft's docs have always seemed to me to assume I know a bunch of .NET concepts that I really don't know much about...



More information about the Python-list mailing list