embedding python without dynamically lodaed code in <prefix>

Mike Romberg romberg at smaug.fsl.noaa.gov
Fri Apr 13 13:51:45 EDT 2001


>>>>> " " == Samuel D Gendler <sgendler at akamai.com> writes:

     > I am using libpython.a (2.0, if you must know) in order to gain
     > access to all of the nifty Python data structures.  Currently,
     > we use ONLY the C api.  The application gets distributed to
     > several thousand servers around the planet, none of which have
     > any version of python installed, let alone 2.0, and we really
     > have no interest in doing a python install to several thousand
     > servers.

     > When I call PyInitialize() on a machine that does not have
     > python2.0 installed, it complains like so:

     > Could not find platform independent libraries <prefix> Could
     > not find platform dependent libraries <exec_prefix> Consider
     > setting $PYTHONHOME to <prefix>[:<exec_prefix>] 'import site'
     > failed; use -v for traceback

     > I don't really care that the import fails (assuming that the
     > PyInitialize still succeeds. I haven't checked the source yet),
     > but it would be really nice to be able to supress these error
     > messages, especially if they are having a negative impact on
     > PyInitialize.

     > Any suggestions would be much appreciated.  Please respond to
     > my email as well as any public forum that this might arrive at.

  We do something kinda similar.  In our case we are packing all of
the python runtime library into a pickled file.  So, there is no
library under the prefix that python expects.  I was able to make this
"error" go away by doing the following:

  1 - PyInitialize() tries to load a module called 'site'.  If this
      fails then you get the above error.  I have found no way to get
      PyInitialize() to not try to load site (short of modifying the
      code).

  2 - So, we simply add our own site.py somewhere on the PYTHONPATH.
      If you use the site.py which comes with python then you will
      still get the failure because it attempts to find some kind of
      text file which has something like the license in it.  This is
      kinda a pain since this thing is not a python module and can not
      be pickled or frozen in an embeded app.  We use a modified
      version of the standard python site.py which avoids this
      problem.  You can even freeze site.py into your app (which is
      what we do).

Mike Romberg (romberg at fsl.noaa.gov)






More information about the Python-list mailing list