Get Python without (selected) batteries
I very like the "battery included" philosophy of Python but now I have to perform a slim installation with only core开发者_开发问答 features and some other which I'd like to choose one by one.
Is it possible to download Python with only selected modules?
Install python as normal. Open up the python interpreter and import some of the stuff you think you won't want.
import io, optparse, tarfile
Then the str
representation of the module has its path in it
>>> tarfile
<module 'tarfile' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tarfile.py'>
You can just go in and remove whatever .py
files you dont want in your installation.
Obviously this is dangerous because you don't really know the internal dependencies of the Python modules.
Have a look at py2exe or similar projects. They basically package a Python script with all its dependency in a single executable. It looks like it would be the right thing for you.
If I recall there's also an independent module in py2exe that recursively analyses the dependency of a Python module, I can't find it now though.
I see that there are some folders/libs that I do not use (test, docs, tcl) that take several MBs
ActivePython does not include tests, and provides a install-time option to exclude documentation and PyWin32 (though not for tcl/tkinter - but you can safely delete it after install).
Alternatively you could use PyInstaller to create a customized installer for your app.
AFAIK it's not possible to download Python with only selected modules, but after an install you can remove everything (read: the libraries) you don't need (never going to use JSON? Gone!, etc).
You can start from TinyPy, and add what you needed. However, TinyPy seems to be unmaintained though.
精彩评论