What is the easiest way to build Python26.zip for embedded distribution?

允我心安 提交于 2019-12-12 09:48:16

问题


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.



来源:https://stackoverflow.com/questions/789598/what-is-the-easiest-way-to-build-python26-zip-for-embedded-distribution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!