Set python command option -OO

52 views
Skip to first unread message

Elliot Garbus

unread,
Jan 20, 2024, 4:06:48 AMJan 20
to PyInstaller
How do I set the python command line option -OO.
The objective is to disable assert statements and remove docstrings.

It appears the -OO option is not supported.  Is this correct?

bwoodsend

unread,
Jan 20, 2024, 11:26:41 AMJan 20
to PyInstaller

You can use:

exe = EXE( pyz, a.scripts, [('O', None, 'OPTION'), ('O', None, 'OPTION')], ...

but, whilst it does set sys.flags.optimize to 2, it doesn’t remove either the assertions or docstrings since they need to happen at compile time. You used to be able to use python -OO -m PyInstaller your-code.py but pycparser (one of PyInstaller’s indirect Windows-only dependencies) doesn’t allow it now. That said, -OO mode is a waste of time. Since the docstrings are small and in a PyInstaller application get compressed, you’re looking at about ~0.1% reduction in application size.

Elliot Garbus

unread,
Jan 20, 2024, 6:15:15 PMJan 20
to PyInstaller
Thank you - that is very helpful.
The desire to remove doc-strings has to do with their desire to keep things "more secure".  
I'm also building a portion of the app in cython, for the same reason.  This is a direct request of my client.

I'll look for a different path to disable asserts and remove doc-strings.  I'm open to suggestions!

Thanks again!

Elliot Garbus

unread,
Jan 22, 2024, 2:59:46 PMJan 22
to PyInstaller
This worked:  python -OO -m PyInstaller --clean -y .\my-specfile.spec
Reply all
Reply to author
Forward
0 new messages