What is the easiest way to build Python26.zip for

2019-05-17 10:11发布

问题:

I am using Python as a plug-in scripting language for an existing C++ application. I am able to embed the python interpreter as stated in the Python documentation. Everything works successfully with the initialization and de-initialization of the interpreter. I am, however, having trouble loading modules because I have not been able to zip up the standard library in to a zip file (normally PythonXX.zip, corresponding to the version number of the python dll).

What is the simplest way to zip up all of the standard library after optimized bytecode compiling? I'm looking for a simple script or command to do so for me, as I really don't want to do this by hand.

Any ideas?

Thanks!

回答1:

It shouldn't be too difficult to write a script for that. Check out the zipfile.PyZipFile class and it's writepy method.



回答2:

I would probably use setuptools to create an egg (basically a java jar for python). The setup.py would probably look something like this:

from setuptools import setup, find_packages

setup(
    name='python26_stdlib',
    package_dir = {'' : '/path/to/python/lib/directory'},
    packages = find_packages(),
    #any other metadata
)

You could run this using python setup.py bdist_egg. Once you have the egg, you can either add it to the python path or you can install it using setuptools. I believe this should also handle the generation of pycs for you as well.

NOTE: I wouldn't use this on my system python directory. You might want to set up a virtualenv for this.