views:

67

answers:

2

I know there is a way to import modules which are in a zip file with python. I created kind of custom python package library in a zip file.

I would like to put as well my "task" script in this package, those are using the library. Then, with bash, I would like to call the desired script in the zip file without extracting the zip.

The goal is to have only one zip to move in a specified folder when I want to run my scripts.

+1  A: 

Have a look at zipimport. It should work directly from the install. You might have to do some work to make the pythonpath point to your zip file/directory.

This module adds the ability to import Python modules (*.py, *.py[co]) and packages from ZIP-format archives. It is usually not needed to use the zipimport module explicitly; it is automatically used by the built-in import mechanism for sys.path items that are paths to ZIP archives.that are paths to ZIP archives.

Rod
What I meant was to run python script inside the zip with bash command in order to create a .command file that is launch the desired script. Maybe it's not possible without python?
ForceMagic
I am not aware of anything that could call a script directly inside a zip archive. Sadly, you have to rely on python to read the python scripts which prevents you from using the __main__ == "__main__" idiom.
Rod
Ok, thanks a lot!Instead, I'll try to find something to create a application like with my python files. Because in the current situation, I need to have only one file that my users can click and the script run with its modules.I was thinking about py2app, because I'm on Mac.
ForceMagic
The best link I found for building app with python script :http://stackoverflow.com/questions/2933/an-executable-python-app
ForceMagic
A: 

I finally found a way to do this. If I create a zip file, I must create _main_.py at the root of the zip. Thus, it is possible to launch the script inside the main and call if from bash with the following command :

python myArchive.zip

This command will run the _main_.py file! :)

Then I can create .command file to launch the script with proper parameters.

Of course you can also put some code in the _main_.py file you give you more flexibility adding some arguments.

ex: python _main_.py buildProject

ForceMagic
Great. I thought you wanted to arbitrarily call "any" script within your zip archive.
Rod
Basically it is what I wanted, but without unzipping the file. So it's the only way I found to do so.
ForceMagic