Seiten

Mittwoch, 17. März 2010

py2exe VC-library woes (part two)

I've got a shiny new desktop pc in my office last week. First thing to setup was my development environment. So among other stuff I installed python (2.6.4), wxpython, py2exe and tested the install with one of my projects.

But generating a stand alone windows executable failed immediately:
python setup.py py2exe
...bailed out with following message:
*** searching for required modules ***
*** parsing results ***
*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory

What happended?

This time I installed python with local admin rights "for all users". As noted in my first post about distributing python apps for windows python >2.6 (on the windows platform) is linked against Microsoft Visual C libraries (VC90) and the preferred way for installing those dependencies is to put them into the Windows\WinSxS system directory - where assemblies can be shared "side by side" among applications.

That's exactly what the python msi installer does when it is given the "install for all users" option with the required admin-privileges. But unfortunately current versions of py2exe don't seem to check system directories when they scan for required modules and thus fail.

The workaround:

You have two options:
  1. Locate the correct version and copy msvcp90.dll and msvcr90.dll into pythons DLLs directory
  2. Install Python without admin rights (for yourself only)

Howto locate required VC DLLs

  • Download getassembly.py into a folder of your choice.
  • Using the windows console execute (make sure to adjust the paths):
    >cd C:\path\to\getassembly
    >python getassembly.py C:\python26\python.exe
  • In the output you'll find the dependentAssembly that holds all information you need to find the correct folder for copying the correct set of DLLs:
    <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
        version="9.0.21022.8" processorArchitecture="x86"
        publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  • In the example above this would be on my system:
    C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375

Montag, 8. Februar 2010

Distributing python apps for the windows platform

So you've kept your python code platform independent and struggled through the process of generating windows executables via a py2exe aware setup.py script? Congratulations - you're ready to create a setup package! But if using a python version >2.6 you'll have to solve the visual C++ runtime issues! Python and your derived apps are linked against VC libraries and contain a version specification (called "assemblies") to access the correct set of DLLs. You can fetch that XML coded info from your python exe or dll files using my script getassembly.py and it will look like this:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>
[EDIT 2010-03-17:] My follow up to this post py2exe VC-library woes (part two) gives infos on how to locate the correct set of DLLs on your system.

You have two packaging options to fullfill the dependencies listed in the manifest:
  1. Install Microsoft.VC90.CRT.manifest, msvcp90.dll and msvcr90.dll as a "private assembly" into the application directory (provided that you have the license to distribute those files).
  2. Preferred: Include the redistributable installer vcredist_x86.exe. It will setup a shared "side by side assembly" into the Windows\WinSxS system directory.
For options on how to perform a silent install read Aaron Stebner's WebLog. Here's my recipe for implementing this in an Inno Setup script: Put this code into the corresponding [files] and [run] sections. Be sure to fix Source: {#MySourceDir}\shared so that it points to vcredist_x86.exe on your system.
[files]
Source: {#MySourceDir}\shared\vcredist_x86.exe; DestDir: {tmp}; Permissions: everyone-full; Flags: ignoreversion overwritereadonly
;...additional [files] options

[run]
Filename: {tmp}\vcredist_x86.exe; Parameters: /qb!; WorkingDir: {tmp}; StatusMsg: Checking for and installing Microsoft Visual C++ Redistributable Package...; Flags: waituntilterminated
;...additional [run] options
This was successfully tested on Windows XP, Vista and 7 with a simple wx application - a stoichiometric calculator. You can download the full source here.

Freitag, 22. Januar 2010

Attention Rocket Scientists! Brauplaner - Prognose Abfüllzeitpunkt

Werte Braugemeinde,

"grün Schlauchen" ist hierzulande weit verbreitet -...und eine der häufigsten Fehlerursachen des handwerklich gebrauten Bieres (Über- oder in selteneren Fällen Unterkarbonisierung). Um den perfekten Kohlensäuregehalt im endvergorenen Bier zu erreichen, muß mit dem Schlauchen so lange zugewartet werden, bis im Jungbier der für die Karbonisierung erforderlichen Restextrakt gerade eben erreicht ist! Grundvoraussetzungen für diese kritische Methode sind:

  1. ein präziser Aräometer (und der sachkundige Umgang mit demselben - s. HBF-Ringversuch 2002)
  2. die genaue Kenntnis des Endvergärungsgrades (Schnellgärprobe)
  3. das Bier ist zum Schlauchzeitpunkt schon relativ gut geklärt (ein dickes Hefesediment in der Flasche / im Keg gibt nur Probleme mit Autolyse)

Sind ALLE diese Punkte erfüllt, ist diese klassisch rustikale Karbonisierungsmethode allen anderen überlegen, denn:

  1. die noch ausreichend vorhandene Gärungsaktivität eliminimiert rasch den zwangsläufig auftretenden Sauerstoffeintrag und schützt das jungfräuliche Bier so vor Oxidation.
  2. sie läßt selbst die enthusiastischesten Anhänger des vom 13. Apostel Wilhelm IV. in Ingolstadt verkündeten 11. Gebotes von 1516 gut schlafen!
  3. für faule Brauer wie mich ist es schlichtweg die Methode mit dem geringsten Zusatzaufwand ;-)

Freilich wäre es nützlich, den exakten Abfüllzeitpunkt voraussagen zu können - schon alleine deshalb, weil eigentlich unsere Liebe zum Bier nicht größer sein darf als unsere Liebe zur Familie ;-) Wer von uns hat nicht schon mal einen Sonntagsspaziergang abgesagt - nur weil er dringend den lezten Sud abfüllen musste - viel Stress, um dann später zu erkennen, dass es sowieso zu früh war, weil der Sud überkarbonisiert endete.

Mein Freund Andreas Magauer - Elektronik- und Mathematikgenie - hat in den letzten Jahren die bedeutendsten Beiträge zu meiner seit 1991 gepflegten Formelsammlung (aka Brauplaner) geleistet. Er hat den Verlauf der Nachgärung mathematisch so nachgebildet, dass der genaue Schlauchzeitpunkt mit 2-3 Messungen auf wenige Stunden genau vorausgesagt werden kann. Ich habe das jetzt ein halbes Jahr getestet und bin sehr beeindruckt und möchte das Ergebnis zur öffentlichen Diskussion / Begutachtung stellen:

http://netbeer.org/downloads/Brauplaner-v5_3.xls
(Register Brauprotokoll ab ca. Zeile 50)

Allzeit Gut Sud!
Hubert Hanghofer