Is there a way to import a Python egg from memory, but not a disk?

Suppose I have a binary string containing a Python egg, all archived. Is there any way to execute and "import" this egg from memory without writing it to disk?

+5
source share
4 answers

Some time ago I looked at pypiserver and could be something similar to what you need: http://pypi.python.org/pypi/pypiserver/0.5.0

Standalone version https://raw.github.com/schmir/pypiserver/standalone/pypi-server-standalone.py

does interesting magic with DictImporter and the zlib library, maybe you can do something like this.

+1
source

- zip , zipimport.zipimporter, ( ) , C.

, :

  • zipimporter, file
  • zipimporter Python, , file -like
  • , , .

, , .

+2

I am not familiar with Python eggs, but try using a StringIO object . Since Python uses duck typing , you can treat it the same way as a file if you do not invoke any specific file methods on it.

-1
source

All Articles