22

I want to run python setup.py install (the setup script uses setuptools), and I want only the .pyc files to be included in the resulting egg or directory. all .py files must not be present. How can I do this ?

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • Write a script reading the ZIP file and removing all unrelated files...that's a three liner. –  Apr 20 '11 at 13:00
  • 1
    @restrisiko: agreed, but maybe there's a standard setuptools method to do it, and if so is the case, I'd like to learn something new about the tools I am using. – Stefano Borini Apr 20 '11 at 13:02

1 Answers1

26

not with install, but a possibility is to run the following command

python setup.py bdist_egg --exclude-source-files

and install the resulting egg in dist with easy_install

easy_install dist/eggname.egg

Note that according to the manual install is nothing but a shortcut to easy_install use.

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • 1
    This will break with python3 because the bytecode files are in __pychache__ and the python interpreter will not look in there unless the source files exist according to [this](https://stackoverflow.com/a/11648547/1071236) – giskou Apr 12 '16 at 11:03
  • 3
    @giskou I tested, it works in Python 3. Since the name of generated pyc file matches the name of original py file, it can be located by the interpreter. – Ken Hung Mar 20 '18 at 08:10