| How to bundle multiple Python sources in one bash script |
|
|
|
| Mittwoch, 13 Oktober 2010 | |
|
Python bietet standardmäßig py2exe an um eine Menge von Python Scripts in einem Windows Executable zusammenzupacken. Danach muss nur dieses exe unter WIndows aufgerufen werden und das Pythonprogramm läuft los. Es ist dazu keine Installation des Programmes notwendig. Da ich kein Windows sondern Linux habe suchte ich nach einer Lösung die mir ein bash Script aus mehreren Python Files erzeugt so dass ich nur eine Datei verteilen muss anstatt den ganzen Satz meiner Python Module.
===> English <===
Python allows to bundle a lot of Python files with py2exe in one executable for Windows. That way a simple call of this exe allows to start the Python program. No installation is required. I don't like windows and use Linux instead. That's why I had to search for a similar solution on Linux. I just want to have all my Python code bundled in one shell script and to be able to distribute one bash file only instead of the whole set of python files.
Dabei bin ich auf diese Seite gestossen. Dann fand ich das Python Cookbook von Oreilly wo
genau diese Methode beschrieben wird - allerdings mit einer
Einschränkung die auf dem ersten Link behoben ist. Leider hatte ich
Probleme, denn immer wenn ich mein generiertes Shellscript aufrief bekam
ich die folgende Fehlermeldung.
traceback (most recent call last):
File "<string>", line 17, in <module> ImportError: No module named main
Die Lösung ist eigentlich recht einfach - wenn man sich mit mit Modules und Packages bei python.org genauer befasst.
Mein Problem war dass ich main in einer Datei collectNWData.py definiert hatte. Nachdem ich im Shell Template Script
import main
main.main()
in
import collectNWData
collectNWData.main()
geändert hatte funtionierte alles wie gewünscht.
===> English <===
I found this site. In addition (because it's referred by the previous site) I found the Python Cookbook from Oreilly. There it's desribed in detail how this method works with some restriction which are removed in the first link. Unfortunately I had problems when I called my generated shell script. Everytime I got.
traceback (most recent call last):
File "<string>", line 17, in <module> ImportError: No module named main
It's not that difficult to fix this - if you read the doc about Modules and Packages on python.org
I had defined a file collectNWData.py which has a main defined. Then I changed in the template script
import main
main.main()
into
import collectNWData
collectNWData.main()
and everything works as expected.
|
|
| Last Updated ( Mittwoch, 07 September 2011 ) |
| < Prev | Next > |
|---|







