Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 286
Don Avatar asked Apr 06 '11 16:04

Don


4 Answers

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.

like image 92
Chris W. Avatar answered Nov 15 '22 13:11

Chris W.


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.

like image 25
UncleZeiv Avatar answered Nov 15 '22 12:11

UncleZeiv


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.

like image 22
Sridhar Ratnakumar Avatar answered Nov 15 '22 11:11

Sridhar Ratnakumar


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).

like image 36
orlp Avatar answered Nov 15 '22 13:11

orlp