should I distribute .pyc files?

Duncan Booth duncan.booth at invalid.invalid
Tue Dec 19 03:49:37 EST 2006


"akbar" <akbarhome at gmail.com> wrote:

> I am creating not-so-important opensource application written in python
> for Linux. I have two files python source in src directory, named
> blabla1.py and blabla2.py. There are byte compiled files too, named
> blabla1.pyc and blabla2.pyc. Should I distribute these files (pyc
> files) to users? If I don't distribute them, and user installed my
> application into /usr (not writable by normal user) then run it as
> normal user, off course, the python cannot make byte-compiled version.
> Will my program runs slower in user computer then in my computer
> because I have byte compiled version?

Short answer: use distutils or build a python egg. These will automate most 
of the distribution process.

Longer answer:

distutils (standard in Python) will build you a variety of installation 
packages such as zip, tar, rpm, or windows .exe (even from linux). The 
installation step will do all necessary compiling from .py to .pyc (and 
also builds extension modules although that can be problematic for a 
windows distribution where the correct compiler almost certainly isn't 
available).

setuptools (http://cheeseshop.python.org/pypi/setuptools) is a collection 
of enhancements to distutils which let you build .egg files. Once you start 
using egg files you can include dependencies between package versions and 
if your product requires a bunch of other packages the installation step 
will download and install the appropriate versions.

See http://peak.telecommunity.com/DevCenter/EasyInstall for instructions on 
installing packages built in this way, but in short, the user has to run 
ez_setup.py from the EasyInstall page, and then a command like:

    	easy_install http://example.com/path/to/MyPackage-1.2.3.tgz

would download and install your package and all the other products it 
depends on. If at a later stage they want to upgrade to a more recent 
version then all they need to do is to run:

    	easy_install --upgrade MyPackage

Installed eggs usually exist in a single file (importable zip) which makes 
uninstalling especially easy: just one file to delete.



More information about the Python-list mailing list